Example #1
0
        // 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"
                });
            });
        }
Example #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc();

            var config = new Config(3);

            services.AddSingleton(config);

            var commandsConnectionString = new CommandConnectionString(Configuration["ConnectionString"]);
            var queriesConnectionString  = new CommandConnectionString(Configuration["QueriesConnectionString"]);

            services.AddSingleton(commandsConnectionString);
            services.AddSingleton(queriesConnectionString);

            services.AddSingleton <SessionFactory>();
            services.AddSingleton <Messages>();
            services.AddHandlers();
        }
Example #3
0
 public PlanContext(CommandConnectionString connString)
 {
     this._connString = connString;
 }