Exemple #1
0
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
     services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();
     TypesToRegister.ForEach(x => { if (x.DeclaringType == null)
                                    {
                                        services.AddScoped(x);
                                    }
                             });
     RegisterService.registerServicesDI(ref services, TypesToRegister);
     services.AddScoped(typeof(IServicesProvider <>), typeof(ServicesProvider <>));
     services.AddScoped(typeof(ICategoryService), typeof(CategoryService));
 }
Exemple #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,

                    ValidIssuer      = "https://localhost:44308",
                    ValidAudience    = "https://localhost:44308",
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(SystemConstants.JWT))
                };
            });
            services.AddMvc(option => option.EnableEndpointRouting = false).SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
            services.AddElmah();
            services.AddSignalR();
            services.AddElmah <ElmahCore.Sql.SqlErrorLog>(options =>
            {
                options.ConnectionString = Configuration.GetConnectionString("simbayuConn"); // DB structure see here: https://bitbucket.org/project-elmah/main/downloads/ELMAH-1.2-db-SQLServer.sql
            });
            services.TryAddSingleton <IHttpContextAccessor, HttpContextAccessor>();
            services.Configure <EmailSettings>(Configuration.GetSection("EmailSettings"));
            // Tenant Services
            // Classes to register
            TypesToRegister.ForEach(x => { if (x.DeclaringType == null)
                                           {
                                               services.AddScoped(x);
                                           }
                                    });
            RegisterRepos.registerReposDI(ref services, TypesToRegister);
            RegisterServices.registerServicesDI(ref services, TypesToRegister);
            //services.AddScopedDynamic<IProductService>(TypesToRegister);
            // Global Service provider
            services.AddScoped(typeof(IServicesProvider <>), typeof(ServicesProvider <>));
            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
            {
                c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
                {
                    Description =
                        "JWT Authorization header using the Bearer scheme. \r\n\r\n Enter 'Bearer' [space] and then your token in the text input below.\r\n\r\nExample: \"Bearer 12345abcdef\"",
                    Name   = "Authorization",
                    In     = ParameterLocation.Header,
                    Type   = SecuritySchemeType.ApiKey,
                    Scheme = "Bearer"
                });

                c.AddSecurityRequirement(new OpenApiSecurityRequirement()
                {
                    {
                        new OpenApiSecurityScheme
                        {
                            Reference = new OpenApiReference
                            {
                                Type = ReferenceType.SecurityScheme,
                                Id   = "Bearer"
                            },
                            Scheme = "oauth2",
                            Name   = "Bearer",
                            In     = ParameterLocation.Header,
                        },
                        new List <string>()
                    }
                });
                // Set the comments path for the Swagger JSON and UI.
                var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
                var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
                c.IncludeXmlComments(xmlPath);
            });
        }