示例#1
0
        public static void Register(IIocManager iocManager)
        {
            var services = new ServiceCollection();

            IdentityCoreBaseRegistrar.Register(services);

            services.AddEntityFrameworkInMemoryDatabase();

            var serviceProvider = WindsorRegistrationHelper.CreateServiceProvider(iocManager.IocContainer, services);

            var sharedBuilder = new DbContextOptionsBuilder <SharedDbContext>();

            sharedBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString()).UseInternalServiceProvider(serviceProvider);

            var microserviceSampleBuilder = new DbContextOptionsBuilder <MicroserviceSampleDbContext>();

            microserviceSampleBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString()).UseInternalServiceProvider(serviceProvider);

            iocManager.IocContainer.Register(
                Component
                .For <DbContextOptions <SharedDbContext> >()
                .Instance(sharedBuilder.Options)
                .LifestyleSingleton(),
                Component
                .For <DbContextOptions <MicroserviceSampleDbContext> >()
                .Instance(microserviceSampleBuilder.Options)
                .LifestyleSingleton()
                );
        }
示例#2
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            //MVC
            services.AddControllersWithViews(
                options =>
            {
                options.Filters.Add(new AbpAutoValidateAntiforgeryTokenAttribute());
            }
                ).AddNewtonsoftJson(options =>
            {
                options.SerializerSettings.ContractResolver = new AbpMvcContractResolver(IocManager.Instance)
                {
                    NamingStrategy = new CamelCaseNamingStrategy()
                };
            });



            IdentityCoreBaseRegistrar.Register(services);
            AuthConfigurer.Configure(services, _appConfiguration);

            services.AddSignalR();

            // Configure CORS for angular2 UI
            services.AddCors(
                options => options.AddPolicy(
                    _defaultCorsPolicyName,
                    builder => builder
                    .WithOrigins(
                        // App:CorsOrigins in appsettings.json can contain more than one address separated by comma.
                        _appConfiguration["App:CorsOrigins"]
                        .Split(",", StringSplitOptions.RemoveEmptyEntries)
                        .Select(o => o.RemovePostFix("/"))
                        .ToArray()
                        )
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    .AllowCredentials()
                    )
                );

            // Swagger - Enable this line and the related lines in Configure method to enable swagger UI
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new OpenApiInfo()
                {
                    Title = "MicroserviceBaseProject API", Version = "v1"
                });
                options.DocInclusionPredicate((docName, description) => true);

                // Define the BearerAuth scheme that's in use
                options.AddSecurityDefinition("bearerAuth", new OpenApiSecurityScheme()
                {
                    Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                    Name        = "Authorization",
                    In          = ParameterLocation.Header,
                    Type        = SecuritySchemeType.ApiKey
                });
            });

            // Configure Abp and Dependency Injection
            return(services.AddAbp <MicroserviceBaseProjectWebHostModule>(
                       // Configure Log4Net logging
                       options => options.IocManager.IocContainer.AddFacility <LoggingFacility>(
                           f => f.UseAbpLog4Net().WithConfig("log4net.config")
                           )
                       ));
        }