Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.Configure <BluePrint>(Configuration.GetSection("Settings"));
            services.Configure <BluePrint>(Configuration.GetSection("Features"));
            services.AddSingleton <IConfiguration>(Configuration);
            services.AddHealthChecks();



            services.AddSingleton <IConfiguration>(Configuration);

            services.AddOptions();
            BusBootStrapper.RegisterEventBus(services, Configuration);
            BootStrapper.RegisterComponents(services, Configuration);

            var container = new ContainerBuilder();

            container.Populate(services);
            return(new AutofacServiceProvider(container.Build()));
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(options =>
            {
                options.Filters.Add(typeof(HttpGlobalExceptionFilter));
                options.Filters.Add(typeof(ValidateModelStateFilter));
            }
                            ).AddControllersAsServices().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.Configure <BluePrint>(Configuration.GetSection("Settings"));
            services.Configure <BluePrint>(Configuration.GetSection("Features"));
            services.AddSingleton <IConfiguration>(Configuration);
            ConfigureAuthService(services);

            services.AddHealthChecks();


            BusBootStrapper.RegisterEventBus(services, Configuration);
            BootStrapper.RegisterComponents(services, Configuration);

            services.AddSwaggerGen(options =>
            {
                options.DescribeAllEnumsAsStrings();
                options.SwaggerDoc("v1", new Info
                {
                    Title          = "Manager HTTP API",
                    Version        = "v1",
                    Description    = "The Manager Service HTTP API",
                    TermsOfService = "Terms Of Service"
                });

                options.AddSecurityDefinition("oauth2", new OAuth2Scheme
                {
                    Type             = "oauth2",
                    Flow             = "implicit",
                    AuthorizationUrl = $"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/authorize",
                    TokenUrl         = $"{Configuration.GetValue<string>("IdentityUrlExternal")}/connect/token",
                    Scopes           = new Dictionary <string, string>()
                    {
                        { "manager", "Manager API" }
                    }
                });

                options.OperationFilter <AuthorizeCheckOperationFilter>();
            });

            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                                  builder => builder.AllowAnyOrigin()
                                  .AllowAnyMethod()
                                  .AllowAnyHeader()
                                  .AllowCredentials());
            });
            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.AddTransient <IJobRepository, JobRepository>();
            services.AddTransient <IIdentityService, IdentityService>();

            services.AddOptions();

            var container = new ContainerBuilder();

            container.Populate(services);

            return(new  AutofacServiceProvider(container.Build()));
        }