Esempio n. 1
0
        /// <summary>
        /// Configures the services used by the application.
        /// </summary>
        /// <param name="services">Collection of services.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            var databaseOptions = new DatabaseOptions();

            _configuration
            .GetSection("Database")
            .Bind(databaseOptions);
            var connectionString = databaseOptions.ConnectionString;
            var databaseProvider = databaseOptions.Provider;

            if (databaseProvider.Equals("MySql", StringComparison.InvariantCultureIgnoreCase))
            {
                services.AddDbContext <HeroContext>(options => options.UseMySql(connectionString));
            }
            else
            {
                services.AddDbContext <HeroContext>(options => options.UseInMemoryDatabase(connectionString));
            }

            services.AddScoped <IHeroRepository, HeroRepository>();
            services.AddScoped <IUnitOfWork, UnitOfWork>();

            services.AddCors(options =>
                             options.AddPolicy("AllowAll", builder =>
                                               builder
                                               .AllowAnyOrigin()
                                               .AllowAnyMethod()
                                               .AllowAnyHeader()));

            services
            .AddMvcCore()
            .AddAuthorization()
            .AddJsonFormatters();

            var identityServerOptions = new IdentityServerOptions();

            _configuration
            .GetSection("IdentityServer")
            .Bind(identityServerOptions);
            services
            .AddAuthentication("Bearer")
            .AddIdentityServerAuthentication(options =>
            {
                options.Authority            = identityServerOptions.Authority;
                options.RequireHttpsMetadata = identityServerOptions.RequireHttpsMetadata;
                options.ApiName = identityServerOptions.ApiName;
            });
        }
Esempio n. 2
0
        /// <summary>
        /// Configures the services used by the application.
        /// </summary>
        /// <param name="services">Collection of services.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            var databaseOptions = new DatabaseOptions();

            _configuration
            .GetSection("Database")
            .Bind(databaseOptions);
            var connectionString = databaseOptions.ConnectionString;
            var databaseProvider = databaseOptions.Provider;

            if (databaseProvider.Equals("MySql", StringComparison.InvariantCultureIgnoreCase))
            {
                services.AddDbContext <HeroContext>(options => options.UseMySql(connectionString));
            }
            else
            {
                services.AddDbContext <HeroContext>(options => options.UseInMemoryDatabase(connectionString));
            }

            services.AddScoped <IHeroRepository, HeroRepository>();
            services.AddScoped <IUnitOfWork, UnitOfWork>();

            services.AddCors(options =>
                             options.AddPolicy("AllowAll", builder =>
                                               builder
                                               .AllowAnyOrigin()
                                               .AllowAnyMethod()
                                               .AllowAnyHeader()));

            services.AddMvc();

            var messagingOptions = new MessagingOptions();

            _configuration
            .GetSection("Messaging")
            .Bind(messagingOptions);

            if (messagingOptions.HasUrl)
            {
                services.AddScoped <IHeroMessagingService, SignalRHeroMessagingService>();
            }
            else
            {
                services.AddScoped <IHeroMessagingService, NoopHeroMessagingService>();
            }
        }