// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddDefaultPolicy(builder => { builder.WithOrigins("http://localhost:4200"); builder.AllowAnyMethod(); builder.AllowAnyHeader(); builder.AllowCredentials(); }); }); services.AddControllers() .AddJsonOptions(options => { options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); options.JsonSerializerOptions.IgnoreNullValues = true; }); services.AddDbContext <ShoppingDataContext>(options => options.UseSqlServer(Configuration.GetConnectionString("shopping")) ); ////var mapperConfiguration = Configuration.GetValue<ConfigurationForMapper>("Mapper"); //services.Configure<ConfigurationForMapper>(Configuration.GetSection("Mapper")); // this is what we are going to use for Automapper... var configForMapper = new ConfigurationForMapper(); Configuration.GetSection(configForMapper.SectionName).Bind(configForMapper); // This sets up an IOptions<ConfigurationForMapper> that we can inject into other dependencies. services.Configure <ConfigurationForMapper>(Configuration.GetSection(configForMapper.SectionName)); var mapperConfig = new MapperConfiguration(opt => { opt.AddProfile(new CatalogProfile(configForMapper)); }); IMapper mapper = mapperConfig.CreateMapper(); services.AddSingleton <IMapper>(mapper); services.AddSingleton <MapperConfiguration>(mapperConfig); services.AddScoped <IDoCurbsideQueries, EntityFrameworkCurbsideData>(); services.AddScoped <IDoCurbsideCommands, EntityFrameworkCurbsideData>(); services.AddSingleton <CurbsideChannel>(); services.AddHostedService <CurbsideOrderProcessor>(); // spin this thing up and get it running right now. services.AddSignalR(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers() .AddJsonOptions(options => { options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); options.JsonSerializerOptions.IgnoreNullValues = true; }); services.AddDbContext <ShoppingDataContext>(options => options.UseSqlServer(Configuration.GetConnectionString("shopping")) ); //var mapperConfiguration = Configuration.GetSection<ConfigurationForMapper>("Mapper"); // services.Configure<ConfigurationForMapper>(Configuration.GetSection("Mapper")); // this is what we are going to use for Automapper var configForMapper = new ConfigurationForMapper(); Configuration.GetSection(configForMapper.SectionName).Bind(configForMapper); // this sets up an IOptions<ConfigurationForMapper> that we can inject into other dependencies services.Configure <ConfigurationForMapper>(Configuration.GetSection(configForMapper.SectionName)); var mapperConfig = new MapperConfiguration(opt => { opt.AddProfile(new CatalogProfile(configForMapper)); }); IMapper mapper = mapperConfig.CreateMapper(); services.AddSingleton <IMapper>(mapper); services.AddSingleton <MapperConfiguration>(mapperConfig); services.AddTransient <IDoCurbsideQueries, EntityFrameworkCurbsideData>(); services.AddScoped <IDoCurbsideCommands, EntityFrameworkCurbsideData>(); services.AddSingleton <CurbsideChannel>(); services.AddHostedService <CurbsideOrderProcessor>(); }