Beispiel #1
0
        /// <summary>
        /// Configures the services to add to the ASP.NET Core Injection of Control (IoC) container. This method gets
        /// called by the ASP.NET runtime. See
        /// http://blogs.msdn.com/b/webdev/archive/2014/06/17/dependency-injection-in-asp-net-vnext.aspx
        /// </summary>
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            IServiceProvider provider = services
                                        .AddCorrelationIdFluent()
                                        .AddCustomCaching()
                                        .AddCustomOptions(this.configuration)
                                        .AddCustomRouting()
                                        .AddResponseCaching()
                                        .AddCustomResponseCompression()
                                        .AddDbContext <MatchmakingContext>(options => options.UseInMemoryDatabase(databaseName: "Matchmaking"))
                                        .AddCustomStrictTransportSecurity()
                                        .AddCustomHealthChecks()
                                        .AddCustomSwagger()
                                        .AddHttpContextAccessor()
                                        // Add useful interface for accessing the ActionContext outside a controller.
                                        .AddSingleton <IActionContextAccessor, ActionContextAccessor>()
                                        // Add useful interface for accessing the IUrlHelper outside a controller.
                                        .AddScoped(x => x
                                                   .GetRequiredService <IUrlHelperFactory>()
                                                   .GetUrlHelper(x.GetRequiredService <IActionContextAccessor>().ActionContext))
                                        .AddCustomApiVersioning()
                                        .AddVersionedApiExplorer(x => x.GroupNameFormat = "'v'VVV") // Version format: 'v'major[.minor][-status]
                                        .AddMvcCore()
                                        .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
                                        .AddApiExplorer()
                                        .AddAuthorization()
                                        .AddDataAnnotations()
                                        .AddJsonFormatters()
                                        .AddCustomJsonOptions(this.hostingEnvironment)
                                        .AddCustomCors()
                                        .AddCustomMvcOptions(this.hostingEnvironment)
                                        .Services
                                        .AddProjectCommands()
                                        .AddProjectMappers()
                                        .AddProjectRepositories()
                                        .AddProjectServices()
                                        .BuildServiceProvider();

            RandomSeed.Initialize(provider);
            return(provider);
        }