// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMediatR(typeof(Startup).Assembly); services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); // Register MCC database //services.AddDbContext<MccDatabaseContext>(options => options.UseSqlServer(Configuration["ConnectionStrings:MccConnection"])); // Register Mongo data store var mongoContext = new LpcsMongoContext(connectionString: Configuration["Mongo:ConnectionString"]); services.AddSingleton <LpcsMongoContext>(mongoContext); //services.AddScoped<LpcsMongoContext>(mongoContext); // Config Azure AD B2C stuff services.AddAuthentication(options => { options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(jwtOptions => { jwtOptions.Authority = $"https://login.microsoftonline.com/tfp/{Configuration["AzureAdB2C:Tenant"]}/{Configuration["AzureAdB2C:Policy"]}/v2.0/"; jwtOptions.Audience = Configuration["AzureAdB2C:ClientId"]; // NOTE: Do not use this handler in Production. jwtOptions.Events = new JwtBearerEvents { OnAuthenticationFailed = AuthenticationFailed }; }); // Config object mappings var config = new AutoMapper.MapperConfiguration(cfg => { cfg.AddProfile(new AutoMapperProfileConfiguration()); }); var mapper = config.CreateMapper(); services.AddSingleton(mapper); // Add framework services. services.AddMvc(); // Register application services services.AddScoped <IProfileProvider, ProfileProvider>(); services.AddScoped <ILogProvider, LogProvider>(); }
public LogProvider(LpcsMongoContext context, AutoMapper.IMapper mapper) { _context = context; _mapper = mapper; }