public void ConfigureContainer(ServiceRegistry services) { // Supports ASP.Net Core DI abstractions services.AddOptions(); services.Configure <KafkaOptions>(Configuration.GetSection("Kafka")); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Order APIs", Version = "v1" }); }); services.AddEntityFrameworkSqlServer() .AddDbContext <OrdersDBContext>(options => { options.UseSqlServer(Configuration["ConnectionString"], sqlServerOptionsAction: sqlOptions => { sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name); sqlOptions.EnableRetryOnFailure(maxRetryCount: 3, maxRetryDelay: TimeSpan.FromSeconds(1), errorNumbersToAdd: null); }); }); services.AddMvc() .AddJsonOptions(options => { options.JsonSerializerOptions.IgnoreNullValues = true; }); services.AddLogging(); services.AddControllers(); services.Scan(scanner => { scanner.AssemblyContainingType <CreateOrderCommand>(); scanner.AssemblyContainingType <CreateItemCommand>(); scanner.AssemblyContainingType <CreateItemsCommand>(); scanner.AssemblyContainingType <RollbackOrderCommand>(); scanner.AssemblyContainingType <GetItemQuery>(); scanner.AssemblyContainingType <GetItemsQuery>(); scanner.ConnectImplementationsToTypesClosing(typeof(IRequestHandler <,>)); }); services.For <IMediator>().Use <Mediator>().Transient(); services.For <ServiceFactory>().Use(ctx => ctx.GetInstance); services.For(typeof(IItemRepository)).Add(typeof(ItemRepository)).Singleton(); services.For(typeof(IOrderRepository)).Add(typeof(OrderRepository)).Singleton(); services.For(typeof(IKafkaProducer <>)).Add(typeof(KafkaProducer <>)).Singleton(); services.For(typeof(IKafkaSubscriber <>)).Add(typeof(KafkaSubscriber <>)).Singleton(); services.For(typeof(IKafkaMessageService <,>)).Add(typeof(KafkaMessageService <,>)).Singleton(); services.AddCors(options => { options.AddDefaultPolicy(builder => { builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader(); }); }); // services.AddHostedService<PaymentBackgroundAvroService>(); // services.AddHostedService<PaymentBackgroundJsonService>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureContainer(ServiceRegistry services) { services.AddControllersWithViews().AddControllersAsServices().AddJsonOptions(x => { x.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); x.JsonSerializerOptions.MaxDepth = 255; }); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); services.AddEntityFrameworkSqlServer(); services.AddSwaggerGen(c => { c.AddServer(new OpenApiServer { Url = "http://localhost:5000", Description = "HTTP endpoint" }); c.AddServer(new OpenApiServer { Url = "https://localhost:5001", Description = "HTTP endpoint with SSL" }); c.SwaggerDoc("v1", new OpenApiInfo { Title = "Where Is My Fleet API", Version = "v1" }); c.CustomSchemaIds((t) => { return(t.FullName.Replace("+", "")); }); }); //var applicationServicesAssembly = Assembly.Load(); services.AddMediatR(typeof(WhereIsMyFleet.Services.CurrentUserModel).Assembly); services.For <IConfiguration>().Use(Configuration); services.AddDbContext <WhereIsMyFleetDbContext>(o => o.UseSqlServer(Configuration.GetConnectionString("WhereIsMyFleet"))); services.SetupRegistries(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureContainer(ServiceRegistry services) { services.AddMvc().AddControllersAsServices() .AddJsonOptions(x => { x.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); x.JsonSerializerOptions.MaxDepth = 255; }); services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp"; }); services.AddEntityFrameworkSqlServer(); #region setupAuthAndSwagger services.AddAuthentication(c => { c.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; c.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { // Clock skew compensates for server time drift. // We recommend 5 minutes or less: ClockSkew = TimeSpan.FromMinutes(5), // Specify the key used to sign the token: IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("VerticalToDoKeyVerticalToDoKeyVerticalToDoKey")), RequireSignedTokens = true, // Ensure the token hasn't expired: RequireExpirationTime = true, ValidateLifetime = true, // Ensure the token audience matches our audience value (default true): ValidateAudience = false, // Ensure the token was issued by a trusted authorization server (default true): ValidateIssuer = false, }; }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Vertical ToDo API", Version = "v1" }); c.CustomSchemaIds((t) => { return(t.FullName.Replace("+", "")); }); c.AddSecurityDefinition(JwtBearerDefaults.AuthenticationScheme, new OpenApiSecurityScheme { Name = "Authorization", Type = SecuritySchemeType.ApiKey, Scheme = JwtBearerDefaults.AuthenticationScheme, BearerFormat = "JWT", In = ParameterLocation.Header, Description = "JWT Authorization header using the Bearer scheme." }); c.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = JwtBearerDefaults.AuthenticationScheme } }, new string[] {} } }); }); #endregion services.For <IConfiguration>().Use(Configuration); services.For <IHttpContextAccessor>().Use <HttpContextAccessor>(); services.AddDbContext <VerticalToDoDbContext>(o => o.UseSqlServer(Configuration.GetConnectionString("VerticalToDo"))); services.SetupRegistries(); var c = new Container(services); var a = c.Model.For <AccountsController>().Default.DescribeBuildPlan(); var q = c.WhatDoIHave(); }