public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              IApplicationLifetime applicationLifetime)
        {
            var container = app.ApplicationServices.GetService <IKernel>();

            var componentContainer = new NinjectComponentContainer(container);

            componentContainer.Register <IHttpContextAccessor, HttpContextAccessor>();
            componentContainer.Register <IDatabaseContextCache, ContextDatabaseContextCache>();

            var applicationPartManager = app.ApplicationServices.GetRequiredService <ApplicationPartManager>();
            var controllerFeature      = new ControllerFeature();

            applicationPartManager.PopulateFeature(controllerFeature);

            foreach (var type in controllerFeature.Controllers.Select(t => t.AsType()))
            {
                componentContainer.Register(type, type);
            }

            ServiceBus.Register(componentContainer);

            var databaseContextFactory = componentContainer.Resolve <IDatabaseContextFactory>();

            databaseContextFactory.ConfigureWith("DocumentStore");

            _bus = ServiceBus.Create(componentContainer).Start();

            applicationLifetime.ApplicationStopping.Register(OnShutdown);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseCors(
                options => options.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()
                );

            app.UseHttpsRedirection();
            app.UseMvc();
        }
        public void CanBindMultipleNamed()
        {
            // ARRANGE
            var kernel    = new StandardKernel();
            var container = new NinjectComponentContainer(kernel);

            // ReSharper disable once ObjectCreationAsStatement
            new REstateHost(container);

            // ACT
            container.Register(typeof(ICartographer <,>), typeof(DotGraphCartographer <,>), "dot");
            container.Register(typeof(ICartographer <,>), typeof(TestCartographer <,>), "test");

            var test = container.Resolve <ICartographer <string, string> >("test");
            var dot  = container.Resolve <ICartographer <string, string> >("dot");

            // ASSERT
            Assert.IsType <TestCartographer <string, string> >(test);
            Assert.IsType <DotGraphCartographer <string, string> >(dot);
        }
Beispiel #3
0
        public void Start()
        {
            _kernel = new StandardKernel();

            _kernel.Bind <IEMailService>().To <EMailService>();

            var container = new NinjectComponentContainer(_kernel);

            container.Register <IAzureStorageConfiguration, DefaultAzureStorageConfiguration>();
            container.RegisterServiceBus();

            _bus = container.Resolve <IServiceBus>().Start();
        }
        public void CanOverrideABinding()
        {
            // ARRANGE
            var kernel    = new StandardKernel();
            var container = new NinjectComponentContainer(kernel);

            // ReSharper disable once ObjectCreationAsStatement
            new REstateHost(container);

            // ACT
            container.Register(typeof(ICartographer <,>), typeof(TestCartographer <,>));
            var resolvedCartographer = container.Resolve <ICartographer <string, string> >();

            // ASSERT
            Assert.IsType <TestCartographer <string, string> >(resolvedCartographer);
        }
Beispiel #5
0
        private static void Main(string[] args)
        {
            var container = new NinjectComponentContainer(new StandardKernel());

            container.Register <IAzureStorageConfiguration, DefaultAzureStorageConfiguration>();
            container.RegisterServiceBus();

            using (var bus = container.Resolve <IServiceBus>().Start())
            {
                string userName;

                while (!string.IsNullOrEmpty(userName = Console.ReadLine()))
                {
                    bus.Send(new RegisterMemberCommand
                    {
                        UserName = userName
                    });
                }
            }
        }
Beispiel #6
0
        public void Start()
        {
            Log.Assign(new Log4NetLog(LogManager.GetLogger(typeof(Host))));

            if (ConfigurationItem <bool> .ReadSetting("SkipCertificateValidation", true).GetValue())
            {
                ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
            }

            ServicePointManager.Expect100Continue       = false;
            ServicePointManager.MaxServicePointIdleTime = 0;

            _container = new NinjectComponentContainer(_kernel);

            _container.Register <IMalwareService, McAfeeMalwareService>();

            ServiceBus.Register(_container);

            _container.Resolve <IDatabaseContextFactory>().ConfigureWith("DocumentStore");

            _bus = ServiceBus.Create(_container).Start();
        }
Beispiel #7
0
        public static NinjectComponentContainer Create(IKernel kernel, INetMQServerConfiguration configuration)
        {
            Guard.AgainstNull(kernel, nameof(kernel));
            Guard.AgainstNull(configuration, nameof(configuration));

            var container = new NinjectComponentContainer(kernel);

            container.RegisterInstance(configuration);
            container.Register(typeof(ISerializer), configuration.GetSerializerType());
            container.Register <IPipelineFactory, DefaultPipelineFactory>();
            container.Register <INetMQRequestClientProvider, NetMQRequestClientProvider>();
            container.Register <INetMQRequestServer, NetMQRequestServer>();
            container.Register <IUriResolver, DefaultUriResolver>();
            container.Register <IQueueManager, QueueManager>();
            container.Register <INetMQServer, NetMQServer>();

            var reflectionService = new ReflectionService();

            foreach (var type in reflectionService.GetTypesAssignableTo <IPipeline>())
            {
                if (type.IsInterface || type.IsAbstract || container.IsRegistered(type))
                {
                    continue;
                }

                container.Register(type, type, Lifestyle.Transient);
            }

            foreach (var type in reflectionService.GetTypesAssignableTo <IPipelineObserver>())
            {
                if (type.IsInterface || type.IsAbstract)
                {
                    continue;
                }

                var interfaceType = type.InterfaceMatching($"I{type.Name}");

                if (interfaceType != null)
                {
                    if (container.IsRegistered(type))
                    {
                        continue;
                    }

                    container.Register(interfaceType, type, Lifestyle.Singleton);
                }
            }

            var queueFactoryType = typeof(IQueueFactory);
            var queueFactoryImplementationTypes = new HashSet <Type>();

            void AddQueueFactoryImplementationType(Type type)
            {
                queueFactoryImplementationTypes.Add(type);
            }

            if (configuration.ScanForQueueFactories)
            {
                foreach (var type in new ReflectionService().GetTypesAssignableTo <IQueueFactory>())
                {
                    AddQueueFactoryImplementationType(type);
                }
            }

            foreach (var type in configuration.QueueFactoryTypes)
            {
                AddQueueFactoryImplementationType(type);
            }

            container.RegisterCollection(queueFactoryType, queueFactoryImplementationTypes, Lifestyle.Singleton);

            var queueManager   = container.Resolve <IQueueManager>();
            var queueFactories = container.ResolveAll <IQueueFactory>();

            foreach (var queueFactory in queueFactories)
            {
                queueManager.RegisterQueueFactory(queueFactory);
            }

            return(container);
        }