// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Connection strings var commandConnection = new CommandConnectionString( Configuration.GetConnectionString("CommandConnection") ); var queryConnection = new QueryConnectionString( Configuration.GetConnectionString("QueryConnection") ); services.AddSingleton(commandConnection); services.AddSingleton(queryConnection); //Command Repositories services.AddSingleton <PlanContext>(); services.AddSingleton <coreInt.IUnitOfWork, PlanContext>(); services.AddTransient <coreInt.IPlanificationRepository, repos.PlanificationRepository>(); services.AddTransient <coreInt.IRepository <core.Client, string>, repos.ClientRepository>(); services.AddTransient <coreInt.ICropTypeRepostitory, repos.CropTypeRepository>(); services.AddDbContext <PlanContext>(); //FluentValidation services.AddControllers() .AddNewtonsoftJson() .AddFluentValidation(f => f.RegisterValidatorsFromAssembly(Assembly.GetExecutingAssembly())); services.AddTransient(typeof(IPipelineBehavior <,>), typeof(ValidationBehavior <,>)); //Query Repositories services.AddTransient <ICropRepository, CropRepository>(); services.AddTransient <IPlanificationRepository, PlanificationRepository>(); services.AddMediatR(Assembly.GetExecutingAssembly()); services.AddCors(options => { options.AddPolicy("MyCoresOptions", builder => { builder.WithOrigins("http://localhost:3000"); }); }); services.AddSwaggerGen(o => { o.SwaggerDoc("v1", new OpenApiInfo { Title = "Planification API", Version = "v1" }); }); }
protected override void Load(ContainerBuilder builder) { builder.RegisterType <FeedRepository>().As <IFeedRepository>(); builder.RegisterAssemblyTypes(typeof(IQueryHandler <,>).Assembly) .AsClosedTypesOf(typeof(IQueryHandler <,>)); builder.RegisterAssemblyTypes(typeof(ICommandHandler <>).Assembly) .AsClosedTypesOf(typeof(ICommandHandler <>)); builder.RegisterGenericDecorator(typeof(LoggingCommandDecorator <>), typeof(ICommandHandler <>)); builder.RegisterDecorator <CachedGetFeedNewsQueryHandler, IQueryHandler <GetFeedNewsQuery, News[]> >(); var queryConnectionString = new QueryConnectionString(_configuration.GetConnectionString("Default")); builder.RegisterInstance(queryConnectionString).As <IQueryConnectionString>().SingleInstance(); builder.RegisterType <RequestHandler>().SingleInstance(); builder.RegisterType <ParserProcessor>().As <IParserProcessor>().SingleInstance(); builder.RegisterType <MemoryCache>().As <IMemoryCache>().SingleInstance(); }
public PlanificationRepository(QueryConnectionString connString) : base(connString.Value) { }