// ConfigureContainer is where you can register things directly // with Autofac. This runs after ConfigureServices so the things // here will override registrations made in ConfigureServices. // Don't build the container; that gets done for you by the factory. public void ConfigureContainer(ContainerBuilder builder) { // Register your own things directly with Autofac here. Don't // call builder.Populate(), that happens in AutofacServiceProviderFactory // for you. IModelBuilder modelBuilder = new ModelBuilder(); builder.RegisterInstance(modelBuilder); AccountServiceResolver.RegisterAccountServices(builder, modelBuilder); SecurityServiceResolver.RegisterSecurityServices(builder, modelBuilder); CommonServiceResolver.RegisterCommonServices(builder, modelBuilder); InfrastructureServiceResolver.RegisterInfrastructureServices(builder); }
// ConfigureServices is where you register dependencies. This gets // called by the runtime before the ConfigureContainer method, below. public void ConfigureServices(IServiceCollection services) { // Add services to the collection. Don't build or return // any IServiceProvider or the ConfigureContainer method // won't get called. Don't create a ContainerBuilder // for Autofac here, and don't call builder.Populate() - that // happens in the AutofacServiceProviderFactory for you. List <Type> tenantControllerTypes = GetTenantControllerTypes().ToList(); List <Type> commonControllerTypes = GetCommonControllerTypes().ToList(); services .AddOptions() .AddAuthorization() .AddControllers() .ConfigureApplicationPartManager(apm => { apm.FeatureProviders.Add(new GenericControllerFeatureProvider(commonControllerTypes, tenantControllerTypes)); }) .SetCompatibilityVersion(CompatibilityVersion.Latest) .AddJsonOptions(options => { options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; options.JsonSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase; }); services .AddMvc() .AddFluentValidation(); services.AddSwaggerDocument(); AddApiVersioning(services, tenantControllerTypes, commonControllerTypes); InfrastructureServiceResolver.RegisterServices(services, Configuration); RegisterMediatRRequestHandlers(services); }