コード例 #1
0
ファイル: Startup.cs プロジェクト: Lazoror/GameStore
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.Configure <DatabaseSettings>(Configuration.GetSection("DatabaseSettings"));
            services.AddSingleton <IDatabaseSettings>(x => x.GetService <IOptions <DatabaseSettings> >().Value);

            // DB Configuration
            var connection = Configuration.GetConnectionString("MyConnection");

            services.AddDbContext <GameContext>
                (options => options.UseSqlServer(connection));

            MongoConfiguration.Configure();

            ConfigureAuthorization(services);

            // Auto Mapper Configuration
            var     mappingConfig = new MapperConfiguration(mc => { mc.AddProfile(new MappingProfile()); });
            IMapper mapper        = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);

            ConfigureLocalization(services);

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            // Autofac configuration
            var builder   = ConfigureAutofac(services);
            var container = builder.Build();

            return(container.Resolve <IServiceProvider>());
        }
コード例 #2
0
 public static void RegisterDependencies(this IServiceCollection services)
 {
     MongoConfiguration.Configure();
     services.TryAddScoped <IMongoContext, MongoContext>();
     services.TryAddScoped <IArticlesWriteRepository, ArticlesWriteRepository>();
     services.TryAddScoped <IArticlesMongoRepository, ArticlesMongoRepository>();
 }
コード例 #3
0
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);
            MongoConfiguration dataConfiguration = new MongoConfiguration();

            dataConfiguration.Configure();
        }
コード例 #4
0
        protected void Application_Start()
        {
            IocConfig.Configure(new HttpConfiguration());
            GlobalConfiguration.Configure(WebApiConfig.Register);
            IConfiguration dataConfiguration = new MongoConfiguration();

            dataConfiguration.Configure();
        }
コード例 #5
0
        public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
        {
            MongoConfiguration.Configure();

            var client       = new MongoClient(configuration.GetSection("MongoDbSettings").GetSection("ConnectionString").Value);
            var databaseName = configuration.GetSection("MongoDbSettings").GetSection("DatabaseName").Value;
            var database     = client.GetDatabase(databaseName);

            services.AddScoped <IMongoContext>(provider => new MongoContext(database, client, provider.GetRequiredService <ICurrentUserService>()));
            services.AddScoped <IUnitOfWork, UnitOfWork>();
            services.AddScoped <IProductRepository, ProductRepository>();
            services.AddScoped <IDomainEventService, DomainEventService>();

            services.AddTransient <IDateTime, DateTimeService>();
            services.AddTransient <ICsvFileBuilder, CsvFileBuilder>();

            return(services);
        }