public static IServiceCollection AddApplicationCommands(this IServiceCollection services) { Assembly assembly = Assembly.GetExecutingAssembly(); services.AddEfCoreSqlServerDb(); services.AddMediatR(assembly); services.AddValidatorsFromAssembly(assembly); services.AddScoped(typeof(IPipelineBehavior<,>), typeof(EndRequestPipelineBehavior<,>)); StronglyTypedIdTypeDescriptor.AddStronglyTypedIdConverter((idType) => { var typeOfIdentity = typeof(StronglyTypedIdConverter<>).MakeGenericType(idType); TypeDescriptor.AddAttributes(idType, new TypeConverterAttribute(typeOfIdentity)); }); return services; }
public static IServiceCollection AddApplicationQueries(this IServiceCollection services) { services.AddScoped <SqlServerDbConnectionFactory>(provider => { var configuration = provider.GetRequiredService <IConfiguration>(); var connectionString = configuration.GetConnectionString("DefaultDb"); return(new SqlServerDbConnectionFactory(connectionString)); }); services.AddMediatR(typeof(SqlServerDbConnectionFactory).Assembly); services.AddValidatorsFromAssembly(typeof(SqlServerDbConnectionFactory).Assembly); StronglyTypedIdTypeDescriptor.AddStronglyTypedIdConverter((idType) => { var idTypeHandler = typeof(StronglyTypedIdMapper <>).MakeGenericType(idType); var idTypeHandlerInstance = (SqlMapper.ITypeHandler)Activator.CreateInstance(idTypeHandler); SqlMapper.AddTypeHandler(idType, idTypeHandlerInstance); }); return(services); }