コード例 #1
0
ファイル: DatabaseFixture.cs プロジェクト: rgonek/peent
        static DatabaseFixture()
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json", true, true)
                          .AddEnvironmentVariables();

            FakeCurrentContextService = new FakeCurrentContextService();
            Configuration             = builder.Build();

            var services = new ServiceCollection();

            ConfigureServices(services);
            ScopeFactory = services.BuildServiceProvider()
                           .GetService <IServiceScopeFactory>();
            Checkpoint = new Checkpoint
            {
                TablesToIgnore = new[]
                {
                    "__EFMigrationsHistory"
                }
            };

            if (IsGithubActions == false)
            {
                EnsureDatabase().GetAwaiter().GetResult();
            }
        }
コード例 #2
0
ファイル: Startup.cs プロジェクト: rgonek/peent
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy(MyAllowSpecificOrigins,
                                  builder =>
                {
                    builder.WithOrigins("http://localhost:3000").AllowAnyHeader().AllowAnyMethod();
                });
            });

            services.AddControllers(options =>
            {
                var workerProvider           = options.ModelBinderProviders.First(p => p.GetType() == typeof(ComplexObjectModelBinderProvider));
                var workerProviderIndex      = options.ModelBinderProviders.IndexOf(workerProvider);
                var paginationBinderProvider = new PaginationModelBinderProvider(workerProvider);
                var sortsBinderProvider      = new SortsModelBinderProvider(paginationBinderProvider);
                var filtersBinderProvider    = new FiltersModelBinderProvider(sortsBinderProvider);
                options.ModelBinderProviders.Insert(workerProviderIndex, paginationBinderProvider);
                options.ModelBinderProviders.Insert(workerProviderIndex, sortsBinderProvider);
                options.ModelBinderProviders.Insert(workerProviderIndex, filtersBinderProvider);

                options.ModelMetadataDetailsProviders.Insert(0, new DateTimeBinderProvider());
            })
            .AddHybridModelBinder()
            .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <GetCategoryQueryValidator>())
            .AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase));
            });

            services.AddDbContext <ApplicationDbContext>(options =>
                                                         options.UseSqlServer(
                                                             Configuration.GetConnectionString("DefaultConnection")));

            services.AddIdentityCore <ApplicationUser>()
            .AddEntityFrameworkStores <ApplicationDbContext>();

            services.AddScoped <IApplicationDbContext>(sp => sp.GetRequiredService <ApplicationDbContext>());
            services.AddHttpContextAccessor();
            var fakeCurrentContextService = new FakeCurrentContextService(Guid.Parse("E78EECD3-87CA-4DBA-B5B2-861BC5A65F4A"), 1);

            services.AddSingleton <ICurrentContextService>(provider => fakeCurrentContextService);
//            services.AddScoped<ICurrentContextService, FakeCurrentContextService>();
//            services.AddScoped<IUserAccessor, UserAccessor>();

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "Peent API", Version = "V1"
                });
            });

            services.AddMediatR(typeof(GetCategoryQueryHandler));
            services.AddScoped(
                typeof(IPipelineBehavior <,>),
                typeof(TransactionBehavior <,>));
            services.AddScoped(
                typeof(IPipelineBehavior <,>),
                typeof(LoggingBehavior <,>));
            services.AddScoped(
                typeof(IPipelineBehavior <,>),
                typeof(PerformanceBehaviour <,>));
            services.AddScoped(typeof(IExistsInCurrentContextValidator <>), typeof(ExistsInCurrentContextValidator <>));
            services.AddScoped <IExistsInCurrentContextValidatorProvider, ExistsInCurrentContextValidatorProvider>();
            services.AddScoped <IUniqueInCurrentContextValidatorProvider, UniqueInCurrentContextValidatorProvider>();
        }