示例#1
0
        public void ConfigureServices(IServiceCollection services)
        {
            var config = ProjectConfiguration.OverrideWithEnvironment();

            services.AddScoped <IProductRepository, ProductRepository>();
            services.AddScoped <ITransactionRepository, TransactionRepository>();
            services.AddScoped <IUserRepository, UserRepository>();

            services.AddScoped <ProductService>();
            services.AddScoped <TransactionService>();
            services.AddScoped <UserService>();

            //todo тут надо бы припилить выбор базы данных от environment variables
            services.AddScoped <IUnitOfWorkFactory>(provider => EfUnitOfWorkFactory.CreateMsSqlBy(config.DbSettings.ConnectionString));

            services.AddMvc();

            //добавление swagger
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc(name: "v1", info: new Info
                {
                    Title = "ControlPanel"
                });

                c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory,
                                                  $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"));
            });

            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
        }
示例#2
0
        public IUnitOfWorkFactory CreateUnitOfWorkFactory()
        {
            switch (DbType)
            {
            case DbType.MsSql:
                return(EfUnitOfWorkFactory.CreateMsSqlBy(ConnectionString));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }