Пример #1
0
        static void Main(string[] args)
        {
            var bootstrapper = new WindsorBootstrapper
                               (
                directory: AppDomain.CurrentDomain.BaseDirectory, //the directory where to look for assemblies
                filter: "*.*"                                     //the default filer is *.dll, but this is and exe so we need to include it to
                               );

            //the bootstrap process will look for any class
            //the implements the IWindsorInstaller inetrface
            //and is exported via MEF
            var container = bootstrapper.Boot();

            var config = new BusConfiguration();

            config.UsePersistence <InMemoryPersistence>();
            config.UseSerialization <JsonSerializer>();
            config.UseTransport <RabbitMQTransport>()
            .ConnectionString("host=localhost");

            config.UseContainer <NServiceBus.WindsorBuilder>(c =>
            {
                c.ExistingContainer(container);
            });
        }
Пример #2
0
        public void Resolve_INIFile_ShouldResolveNewINIFileFromApplicationFolder()
        {
            //---------------Set up test pack-------------------
            var asmPath   = new Uri(typeof(WindsorBootstrapper).Assembly.CodeBase).LocalPath;
            var asmFolder = Path.GetDirectoryName(asmPath);
            var iniPath   = Path.Combine(asmFolder, Constants.CONFIG_FILE);

            using (new AutoDeleter(iniPath))
            {
                var iniFile  = new INIFile(iniPath);
                var expected = GetRandomInt(5, 55).ToString();
                iniFile["settings"]["RefreshIntervalInMinutes"] = expected;
                iniFile.Persist();
                var container = WindsorBootstrapper.Bootstrap();
                //---------------Assert Precondition----------------
                Assert.IsTrue(File.Exists(iniPath));

                //---------------Execute Test ----------------------
                var resolvedIni = container.Resolve <IINIFile>();
                var result      = resolvedIni["settings"]["RefreshIntervalInMinutes"];

                //---------------Test Result -----------------------
                Assert.AreEqual(expected, result);
            }
        }
Пример #3
0
        public void Configuration(IAppBuilder appBuilder)
        {
            var bootstrapper = new WindsorBootstrapper(AppDomain.CurrentDomain.BaseDirectory, filter: "Divergent.Sales*.*");
            var container    = bootstrapper.Boot();

            var config = new HttpConfiguration();

            config.Formatters.Clear();
            config.Formatters.Add(new JsonMediaTypeFormatter());

            config.DependencyResolver = new WindsorDependencyResolver(container);

            config.Formatters
            .JsonFormatter
            .SerializerSettings
            .ContractResolver = new CamelCasePropertyNamesContractResolver();

            config.MapHttpAttributeRoutes();

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

            appBuilder.UseCors(CorsOptions.AllowAll);
            appBuilder.UseWebApi(config);
        }
Пример #4
0
        public void DefaultConstructor_ShouldUse_ContainerFrom_WindsorBootstrapper()
        {
            // obtuse proof: should resolve the same random INI file setting
            //---------------Set up test pack-------------------
            var asmPath   = new Uri(typeof(WindsorBootstrapper).Assembly.CodeBase).LocalPath;
            var asmFolder = Path.GetDirectoryName(asmPath);
            var iniPath   = Path.Combine(asmFolder, Constants.CONFIG_FILE);

            using (new AutoDeleter(iniPath))
            {
                var iniFile = new INIFile(iniPath);
                iniFile["settings"]["RefreshIntervalInMinutes"] = GetRandomInt(5, 55).ToString();
                iniFile.Persist();
                var referenceContainer = WindsorBootstrapper.Bootstrap();
                var sut = CreateDefault();
                //---------------Assert Precondition----------------
                Assert.IsTrue(File.Exists(iniPath));

                //---------------Execute Test ----------------------
                var resolvedIni = referenceContainer.Resolve <IINIFile>();
                var expected    = resolvedIni["settings"]["RefreshIntervalInMinutes"];
                var result      = sut.WindsorContainer.Resolve <IINIFile>()["settings"]["RefreshIntervalInMinutes"];

                //---------------Test Result -----------------------
                Assert.AreEqual(expected, result);
            }
        }
 public static IWindsorContainer Bootstrap()
 {
     var bootstrapper = new WindsorBootstrapper();
     var container = bootstrapper.Bootstrap();
     var controllerFactory = new WindsorControllerFactory(container.Kernel);
     ControllerBuilder.Current.SetControllerFactory(controllerFactory);
     return container;
 }
        public static WindsorBootstrapper SetupMvc(this WindsorBootstrapper windsorBootstrapper)
        {
            var controllerFactory = new WindsorControllerFactory(windsorBootstrapper.Container.Kernel);

            ControllerBuilder.Current.SetControllerFactory(controllerFactory);

            return(windsorBootstrapper);
        }
        public void Should_be_able_to_create_adapter()
        {
            var buildManager = new Mock<IBuildManager>();
            buildManager.SetupGet(bm => bm.Assemblies).Returns(new[] { GetType().Assembly });

            var bootstrapper = new WindsorBootstrapper(buildManager.Object, new Mock<IBootstrapperTasksRegistry>().Object, new Mock<IPerRequestTasksRegistry>().Object);

            Assert.IsType<WindsorAdapter>(bootstrapper.Adapter);
        }
        public void Should_be_able_to_create_service_locator()
        {
            var buildManager = new Mock<IBuildManager>();
            buildManager.SetupGet(bm => bm.Assemblies).Returns(new[] { GetType().Assembly });

            var bootstrapper = new WindsorBootstrapper(buildManager.Object);

            Assert.IsType<WindsorAdapter>(bootstrapper.ServiceLocator);
        }
Пример #9
0
        protected void Application_Start()
        {
            var basePath = AppDomain.CurrentDomain.BaseDirectory;

            var bootstrapper = new WindsorBootstrapper(Path.Combine(basePath, "bin"));
            var container    = bootstrapper.Boot();

            GlobalConfiguration.Configure(http => WebApiConfig.Register(http, container));
        }
Пример #10
0
        protected void Application_Start()
        {
            var container = new WindsorContainer();

            WindsorBootstrapper.Initialize(container);
            GlobalConfiguration.Configure(WebApiConfig.Register);
            GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator),
                                                               new WindsorCompositionRoot(WindsorBootstrapper.Container));
        }
Пример #11
0
        public void Configuration(IAppBuilder appBuilder)
        {
            Console.Title = typeof(Startup).Namespace;

            var bootstrapper = new WindsorBootstrapper(AppDomain.CurrentDomain.BaseDirectory, filter: "Reservations*.*");
            var container    = bootstrapper.Boot();

            ConfigureNServiceBus(container);
            ConfigureWebAPI(appBuilder, container);
        }
Пример #12
0
 protected void Application_Start()
 {
     WindsorBootstrapper.Initialize();
     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator),
                                                        new WindsorCompositionRoot(WindsorBootstrapper.Container));
 }
Пример #13
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            var container = new WindsorContainer();

            WindsorBootstrapper.Initialize(container);

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Пример #14
0
        protected void Application_Start()
        {
            WindsorBootstrapper.Initialize();
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);

            GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator),
                                                               new WindsorCompositionRoot(WindsorBootstrapper.Container));
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            //Database.SetInitializer<StudentManagementContext>(null);
        }
Пример #15
0
        public override bool OnStart()
        {
            // Turn down the verbosity of traces written by Azure
            RoleEnvironment.TraceSource.Switch.Level = SourceLevels.Information;

            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            // Bootstrap Serilog logger
            // Bootstrap serilog logging
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Information().WriteTo.Trace()
                         .CreateLogger();

            Log.Information("KillrVideo.BackgroundWorker is starting");

            try
            {
                // Initialize the Windsor container
                _windsorContainer = WindsorBootstrapper.CreateContainer();

                // Create the logical worker instances and fire async OnStart
                _logicalWorkers = new ILogicalWorkerRole[]
                {
                    new VideoCatalog.Worker.WorkerRole(_windsorContainer),
                    new Search.Worker.WorkerRole(_windsorContainer),
                    new Uploads.Worker.WorkerRole(_windsorContainer),
                    new SampleData.Worker.WorkerRole(_windsorContainer)
                };

                Task[] startTasks = _logicalWorkers.Select(w => Task.Run(() => w.OnStart())).ToArray();

                // Wait for all workers to start
                Task.WaitAll(startTasks);

                return(base.OnStart());
            }
            catch (AggregateException ae)
            {
                foreach (var exception in ae.Flatten().InnerExceptions)
                {
                    Log.Fatal(exception, "Unexpected exception while starting background worker");
                }

                throw new Exception("Background worker failed to start", ae);
            }
            catch (Exception e)
            {
                Log.Fatal(e, "Unexpected exception while starting background worker");
                throw;
            }
        }
Пример #16
0
        protected void Application_Start()
        {
            var basePath = AppDomain.CurrentDomain.BaseDirectory;

            var bootstrapper = new WindsorBootstrapper(Path.Combine(basePath, "bin"));
            var container    = bootstrapper.Boot();

            container.Register(Component.For <ISalesContext>()
                               .Instance(new SalesContext())
                               .LifestylePerWebRequest());

            GlobalConfiguration.Configure(http => WebApiConfig.Register(http, container));
        }
        public void Should_be_able_to_install_installer()
        {
            var buildManager = new Mock<IBuildManager>();
            buildManager.SetupGet(bm => bm.ConcreteTypes).Returns(new[] { typeof(DummyInstaller) });

            var bootstrapper = new WindsorBootstrapper(buildManager.Object, new Mock<IBootstrapperTasksRegistry>().Object, new Mock<IPerRequestTasksRegistry>().Object);

            DummyInstaller.Installed = true;

            Assert.IsType<WindsorAdapter>(bootstrapper.Adapter);

            Assert.True(DummyInstaller.Installed);
        }
Пример #18
0
        public void Configuration(IAppBuilder appBuilder)
        {
            var bootstrapper = new WindsorBootstrapper(AppDomain.CurrentDomain.BaseDirectory, filter: "Marketing*.*");
            var container    = bootstrapper.Boot();

            var store = CommonConfiguration.CreateEmbeddableDocumentStore("Marketing", session =>
            {
                SeedData.Products().ForEach(s => session.Store(s));
                session.Store(SeedData.HomeStructure());
            });

            container.Register(Component.For <IDocumentStore>().Instance(store).LifestyleSingleton());

            var endpointConfiguration = new EndpointConfiguration("Marketing");

            endpointConfiguration.UseContainer <WindsorBuilder>(c => c.ExistingContainer(container));

            endpointConfiguration.ApplyCommonConfiguration();
            endpointConfiguration.UseRavenPersistence(store);
            endpointConfiguration.LimitMessageProcessingConcurrencyTo(1);

            //var timeoutManager = endpointConfiguration.TimeoutManager();
            //timeoutManager.LimitMessageProcessingConcurrencyTo(4);

            var endpoint = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();

            container.Register(Component.For <IMessageSession>().Instance(endpoint));

            var config = new HttpConfiguration();

            config.Formatters.Clear();
            config.Formatters.Add(new JsonMediaTypeFormatter());

            config.DependencyResolver = new WindsorDependencyResolver(container);

            config.Formatters
            .JsonFormatter
            .SerializerSettings
            .ContractResolver = new CamelCasePropertyNamesContractResolver();

            config.MapHttpAttributeRoutes();

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

            appBuilder.UseCors(CorsOptions.AllowAll);
            appBuilder.UseWebApi(config);
        }
Пример #19
0
        protected void Application_Start()
        {
            var basePath = AppDomain.CurrentDomain.BaseDirectory;

            var bootstrapper = new WindsorBootstrapper(Path.Combine(basePath, "bin"));
            var container    = bootstrapper.Boot();

            var dataManagerComponent = Component.For <IOrderRepository>()
                                       .Instance(new OrderRepository())
                                       .LifestyleSingleton();

            container.Register(dataManagerComponent);

            GlobalConfiguration.Configure(http => WebApiConfig.Register(http, container));
        }
Пример #20
0
        public void  Container_ShouldResolveSingleton_SimpleLoggerFacade()
        {
            //---------------Set up test pack-------------------
            var container = WindsorBootstrapper.Bootstrap();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var result1 = container.Resolve <ISimpleLoggerFacade>();
            var result2 = container.Resolve <ISimpleLoggerFacade>();

            //---------------Test Result -----------------------
            Assert.IsInstanceOf <SimpleLoggerFacade>(result1);
            Assert.IsInstanceOf <SimpleLoggerFacade>(result2);
            Assert.AreEqual(result1, result2);
        }
Пример #21
0
        protected void Application_Start()
        {
            WindsorBootstrapper.Initialize();

            // Configurate WebApi
            GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator),
                                                               new WindsorCompositionRoot(WindsorBootstrapper.Container));
            GlobalConfiguration.Configuration.DependencyResolver = new WindsorDependencyResolver(WindsorBootstrapper.Container);
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            Logger.Info("=====Application Start at:{0}=====", DateTime.Now);
        }
Пример #22
0
		protected override void OnStart( string[] args )
		{
			var baseAddress = ConfigurationManager.AppSettings[ "owin/baseAddress" ];

			var bootstrapper = new WindsorBootstrapper( AppDomain.CurrentDomain.BaseDirectory );
			var windsor = bootstrapper.Boot();

			this._server = new ServerHost(
				baseAddress,
				bootstrapper.ProbeDirectory,
				windsor );

			AddODataSupport( this._server );
			AddSignalRSupport( this._server );

			this._server.Start();
		}
Пример #23
0
        protected override void OnStart(string[] args)
        {
            var baseAddress = ConfigurationManager.AppSettings["owin/baseAddress"];

            var bootstrapper = new WindsorBootstrapper(AppDomain.CurrentDomain.BaseDirectory);
            var windsor      = bootstrapper.Boot();

            this._server = new ServerHost(
                baseAddress,
                bootstrapper.ProbeDirectory,
                windsor);

            AddODataSupport(this._server);
            AddSignalRSupport(this._server);

            this._server.Start();
        }
Пример #24
0
        public override bool OnStart()
        {
            // Turn down the verbosity of traces written by Azure
            RoleEnvironment.TraceSource.Switch.Level = SourceLevels.Information;

            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            // Bootstrap Log4net logging and serilog logger
            XmlConfigurator.Configure();
            _logger    = LogManager.GetLogger(typeof(WorkerRole));
            Log.Logger = new LoggerConfiguration().WriteTo.Log4Net().CreateLogger();

            _logger.Info("KillrVideo.BackgroundWorker is starting");

            try
            {
                // Initialize the Windsor container
                _windsorContainer = WindsorBootstrapper.CreateContainer();

                // Create the logical worker instances
                var logicalWorkers = new ILogicalWorkerRole[]
                {
                    new VideoCatalog.Worker.WorkerRole(_windsorContainer),
                    new Search.Worker.WorkerRole(_windsorContainer),
                    new Uploads.Worker.WorkerRole(_windsorContainer),
                    new SampleData.Worker.WorkerRole(_windsorContainer)
                };

                // Fire OnStart on all the logical workers
                CancellationToken token = _cancellationTokenSource.Token;
                foreach (ILogicalWorkerRole worker in logicalWorkers)
                {
                    ILogicalWorkerRole worker1 = worker;
                    _logicalWorkerTasks.Add(Task.Run(() => worker1.OnStart(token), token));
                }

                return(base.OnStart());
            }
            catch (Exception e)
            {
                _logger.Error("Exception in BackgroundWorker OnStart", e);
                throw;
            }
        }
Пример #25
0
        // This code configures Web API. The Startup class is specified as a type
        // parameter in the WebApp.Start method.
        public void Configuration(IAppBuilder appBuilder)
        {
            var bootstrapper = new WindsorBootstrapper(AppDomain.CurrentDomain.BaseDirectory, filter: "CustomerCare*.*");
            var container    = bootstrapper.Boot();

            var store = CommonConfiguration.CreateEmbeddableDocumentStore("CustomerCare", session =>
            {
                SeedData.Raitings().ForEach(r => session.Store(r));
                SeedData.Reviews().ForEach(r => session.Store(r));
            });

            container.Register(Component.For <IDocumentStore>().Instance(store).LifestyleSingleton());

            var config = new HttpConfiguration();

            config.Formatters.Clear();
            config.Formatters.Add(new JsonMediaTypeFormatter());

            config.DependencyResolver = new WindsorDependencyResolver(container);

            config.Formatters
            .JsonFormatter
            .SerializerSettings
            .ContractResolver = new CamelCasePropertyNamesContractResolver();

            config.MapHttpAttributeRoutes();

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

            HttpServer server = new HttpServer(config);

            config.Routes.MapHttpBatchRoute(
                routeName: "batch",
                routeTemplate: "api/batch",
                batchHandler: new DefaultHttpBatchHandler(server)
                );

            appBuilder.UseCors(CorsOptions.AllowAll);
            appBuilder.UseWebApi(config);
        }
Пример #26
0
		static void Main( string[] args )
		{
			var bootstrapper = new WindsorBootstrapper
			(
				directory: AppDomain.CurrentDomain.BaseDirectory, //the directory where to look for assemblies
				filter: "*.*" //the default filer is *.dll, but this is and exe so we need to include it to
			);

			//the bootstrap process will look for any class 
			//the implements the IWindsorInstaller inetrface
			//and is exported via MEF
			var container = bootstrapper.Boot();

			var config = new BusConfiguration();
			config.UsePersistence<InMemoryPersistence>();
			config.UseContainer<NServiceBus.WindsorBuilder>( c =>
			{
				c.ExistingContainer( container );
			} );
		}
Пример #27
0
        public static async Task Main(string[] args)
        {
            Console.Title = MethodBase.GetCurrentMethod().DeclaringType.Namespace;

            var tcs = new TaskCompletionSource <object>();

            Console.CancelKeyPress += (sender, e) => { tcs.SetResult(null); };

            var basePath = AppDomain.CurrentDomain.BaseDirectory;

            var bootstrapper = new WindsorBootstrapper(basePath, filter: "Divergent*.*");
            var container    = bootstrapper.Boot();

            NServiceBusConfig.Configure(container);

            using (WebApp.Start(new StartOptions("http://localhost:20185"), builder => WebApiConfig.Configure(builder, container)))
            {
                await Console.Out.WriteLineAsync("Web server is running.");

                await Console.Out.WriteLineAsync("Press Ctrl+C to exit...");

                await tcs.Task;
            }
        }
Пример #28
0
 private IWindsorContainer Create()
 {
     return(WindsorBootstrapper.Bootstrap());
 }
 private IMapper Create()
 {
     var bootstrapper = new WindsorBootstrapper(WindsorLifestyles.Transient);
     return bootstrapper.Bootstrap().Resolve<IMapper>();
 }
        private static void AssertExceptionThrownOnRun(WindsorBootstrapper bootstrapper, Type expectedExceptionType,
            string expectedExceptionMessageSubstring, bool defaultConfig)
        {
            bool exceptionThrown = false;

            try
            {
                bootstrapper.Run(defaultConfig);
            }
            catch (Exception ex)
            {
                Assert.AreEqual(expectedExceptionType, ex.GetType());
                StringAssert.Contains(ex.Message, expectedExceptionMessageSubstring);
                exceptionThrown = true;
            }

            if (!exceptionThrown)
            {
                Assert.Fail("Exception not thrown.");
            }
        }
 private static void AssertExceptionThrownOnRun(WindsorBootstrapper bootstrapper, Type expectedExceptionType,
     string expectedExceptionMessageSubstring)
 {
     AssertExceptionThrownOnRun(bootstrapper, expectedExceptionType, expectedExceptionMessageSubstring, true);
 }
Пример #32
0
 public EasyBlockService() : this(WindsorBootstrapper.Bootstrap())
 {
 }