Example #1
0
        private void AddRepositoriesToServices(IServiceCollection services)
        {
            services.AddScoped <IUserRepository, UserRepository>();

            services.Scan(scan => scan
                          .FromAssemblyOf <TcmContext>()
                          .AddClasses(classes => classes.AssignableTo(typeof(IRepositoryMarker)))
                          .AsImplementedInterfaces()
                          .WithScopedLifetime());

            services.Scan(scan => scan
                          .FromAssemblyOf <EducationLevelService>()

                          .AddClasses(classes => classes.AssignableTo(typeof(IApplicationService)))
                          .AsImplementedInterfaces()
                          .WithScopedLifetime());


            services.AddScoped <IUnitOfWork, TcmContextUnitOfWork>();

            var mongoSetting = new MongoSetting();

            //_configuration.Bind("MongoSetting", mongoSetting);

            services.AddScoped <IApiLogService>(x => new ApiLogService(mongoSetting));
        }
Example #2
0
        public void Configuration(IAppBuilder app)
        {
            var builder = new ContainerBuilder();

            builder.RegisterInstance <WeTextConfiguration>(this.configuration).SingleInstance();

            builder.Register(x => new RabbitMqCommandSender(configuration.CommandQueue.ConnectionUri, configuration.CommandQueue.ExchangeName))
            .As <ICommandSender>();

            builder.Register(x => new RabbitMqEventPublisher(configuration.EventQueue.ConnectionUri, configuration.EventQueue.ExchangeName))
            .As <IEventPublisher>();

            builder.RegisterType <RabbitMqMessageSubscriber>()
            .Named <IMessageSubscriber>("CommandSubscriber");

            builder.RegisterType <RabbitMqMessageSubscriber>()
            .Named <IMessageSubscriber>("EventSubscriber");

            var mongoSetting = new MongoSetting
            {
                ConnectionString = configuration.MongoEventStore.ConnectionString,
                CollectionName   = configuration.MongoEventStore.CollectionName,
                DatabaseName     = configuration.MongoEventStore.Database
            };

            builder.Register(x => new MongoDomainRepository(mongoSetting, x.Resolve <IEventPublisher>())).As <IDomainRepository>();

            // Discovers the services.
            DiscoverServices(builder);

            // Register the API controllers within the current assembly.
            builder.RegisterApiControllers(this.GetType().Assembly);

            // Create the container by builder.
            var container = builder.Build();

            // Register the services.
            microServices.AddRange(container.Resolve <IEnumerable <IService> >());

            app.UseAutofacMiddleware(container);

            HttpConfiguration config = new HttpConfiguration();

            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            app.UseAutofacWebApi(config);
            app.UseWebApi(config);
        }
Example #3
0
 public MongoContext(MongoSetting setting)
 {
     _setting = setting;
 }
Example #4
0
 public DefaultMongoDBProvider(IOptions <MongoSetting> setting)
 {
     _setting = setting.Value;
 }