private static void InitialiseIoC() { Trul.Infrastructure.Crosscutting.IoC.IoC.SetContainer(new Trul.Infrastructure.Crosscutting.Windsor.WindsorContainer()); var container = Trul.Infrastructure.Crosscutting.IoC.IoC.Container as Trul.Infrastructure.Crosscutting.Windsor.WindsorContainer; WindsorServiceLocator locator = new WindsorServiceLocator(container.container); ServiceLocator.SetLocatorProvider(() => locator); }
public override void Init() { IServiceLocator injector = new WindsorServiceLocator( new WindsorContainer( new XmlInterpreter( new ConfigResource("oauth.net.components")))); ServiceLocator.SetLocatorProvider(() => injector); }
protected static void InitializeServiceLocator() { IWindsorContainer container = new WindsorContainer(); ComponentRegistrar.AddComponentsTo(container); var windsorServiceLocator = new WindsorServiceLocator(container); DomainEvents.ServiceLocator = windsorServiceLocator; ServiceLocator.SetLocatorProvider(() => windsorServiceLocator); }
private static void SetupServiceLocator() { IServiceLocator injector = new WindsorServiceLocator( new WindsorContainer( new XmlInterpreter( new ConfigResource("oauth.net.components")))); ServiceLocator.SetLocatorProvider(() => injector); }
public void ShouldAllowTwoDifferentContextsToBeLoadedInTheSameAppDomain() { //Arrange var container = new WindsorContainer(); var configuration = new AggregateConfiguration("Test", new IMappingConfiguration[] { new FooMappingConfiguration(), new BarMappingConfiguration() }, null, null, new[] {typeof (Foo), typeof (Bar)}); var secondConfiguration = new AggregateConfiguration("Test", new IMappingConfiguration[] {new FooMappingConfiguration()}, null, null, new[] {typeof (Foo)}); container.Register( Component.For<IAggregateConfiguration>().Instance(configuration).Named(AggregateConfigurationKeyFactory.GenerateKey<Foo,Bar>()), Component.For<IAggregateConfiguration>().Instance(secondConfiguration).Named(AggregateConfigurationKeyFactory.GenerateKey<Foo>())); var windsorServiceLocator = new WindsorServiceLocator(container); ServiceLocator.SetLocatorProvider(() => windsorServiceLocator); IDataContext context = AggregateContextFactory.Create<Foo, Bar>(); IDataContext contextTwo = AggregateContextFactory.Create<Foo>(); var foo = new Foo(); var bar = new Bar(); // Act context.Add(foo); context.Add(bar); contextTwo.Add(foo); // Assert // peek under the covers and ensure that each add went // to the right DbContext. Assert.AreNotEqual(context.GetType().FullName, contextTwo.GetType().FullName); ObjectContext objectContext = ((IObjectContextAdapter) context).ObjectContext; Assert.IsTrue(objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Count() == 2); Assert.IsTrue( objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).First().EntitySet.Name == "Foos"); Assert.IsTrue( objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Last().EntitySet.Name == "Bars"); ObjectContext objectContextTwo = ((IObjectContextAdapter) contextTwo).ObjectContext; Assert.IsTrue(objectContextTwo.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Count() == 1); Assert.IsTrue( objectContextTwo.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Single().EntitySet.Name == "Foos"); }
private void InitWindsor() { container = new WindsorContainer(); container.Register( Component.For(typeof(IUserService)) .ImplementedBy(typeof(UserService)) .Named("UserService").LifeStyle.Singleton); var windsorServiceLocator = new WindsorServiceLocator(container); ServiceLocator.SetLocatorProvider(() => windsorServiceLocator); }
/// <summary> /// Instantiate the container and add all Controllers that derive from /// WindsorController to the container. Also associate the Controller /// with the WindsorContainer ControllerFactory. /// </summary> protected virtual void InitializeServiceLocator() { IWindsorContainer container = new WindsorContainer(); container.Install(FromAssembly.This()); ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container)); var windsorServiceLocator = new WindsorServiceLocator(container); DomainEvents.ServiceLocator = windsorServiceLocator; ServiceLocator.SetLocatorProvider(() => windsorServiceLocator); }
protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); AuthConfig.RegisterAuth(); IServiceLocator injector = new WindsorServiceLocator( new WindsorContainer( new XmlInterpreter( new ConfigResource("oauth.net.components")))); ServiceLocator.SetLocatorProvider(() => injector); Database.SetInitializer<UserContext>(new UserInitializer()); }
public void ShouldAddToTheCorrectContext() { // Arrange var container = new WindsorContainer(); var configuration = new AggregateConfiguration("Test", new IMappingConfiguration[] { new FooMappingConfiguration(), new BarMappingConfiguration() }, null, null, new[] {typeof (Foo), typeof (Bar)}); container.Register( Component.For<IAggregateConfiguration>().Instance(configuration) .Named(AggregateConfigurationKeyFactory.GenerateKey<Foo,Bar>())); string typeName = string.Format("{0},{1}", typeof (Foo).FullName, typeof (Bar).FullName); var windsorServiceLocator = new WindsorServiceLocator(container); ServiceLocator.SetLocatorProvider(() => windsorServiceLocator); IDataContext context = AggregateContextFactory.Create<Foo, Bar>(); var foo = new Foo(); var bar = new Bar(); // Act context.Add(foo); context.Add(bar); // Assert // peek under the covers and ensure that each add went // to the right DbContext. ObjectContext objectContext = ((IObjectContextAdapter) context).ObjectContext; Assert.IsTrue(objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Count() == 2); Assert.IsTrue( objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).First().EntitySet.Name == "Foos"); Assert.IsTrue( objectContext.ObjectStateManager.GetObjectStateEntries(EntityState.Added).Last().EntitySet.Name == "Bars"); }
protected void Application_Start(object sender, EventArgs e) { IWindsorContainer container = new WindsorContainer(); // Register components in code // For XML component registration, see Fire Eagle consumer example container.AddComponentWithLifestyle<ISigningProvider, HmacSha1SigningProvider>( "signing.provider:HMAC-SHA1", LifestyleType.Thread); container.AddComponent<INonceProvider, GuidNonceProvider>(); container.AddComponentWithLifestyle<IRequestStateStore, SessionRequestStateStore>(LifestyleType.Singleton); WindsorServiceLocator injector = new WindsorServiceLocator(container); ServiceLocator.SetLocatorProvider(() => injector); // There is a bug(?) with Twitter's servers at the moment where // POSTing with an Expect header will cause a 417 Expectation Failed // The below prevents .NET from sending Expect headers for all POST // requests in this AppDomain // (see: http://groups.google.com/group/twitter-development-talk/browse_thread/thread/7c67ff1a2407dee7) ServicePointManager.Expect100Continue = false; }
/// <summary> /// Instantiate the container and add all Controllers that derive from /// WindsorController to the container. Also associate the Controller /// with the WindsorContainer ControllerFactory. /// </summary> protected virtual void InitializeServiceLocator() { IWindsorContainer container = new WindsorContainer(); ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container)); container.RegisterControllers(typeof(BaseController).Assembly); ComponentRegistrar.AddComponentsTo(container); var windsorServiceLocator = new WindsorServiceLocator(container); DomainEvents.ServiceLocator = windsorServiceLocator; ServiceLocator.SetLocatorProvider(() => windsorServiceLocator); }
public void Setup() { var container = new WindsorContainer(); var processor = new FakeMessageProcessor(); container.Register(Component.For<FakeMessageProcessor>().Instance(processor)); container.Register( Component.For<IPublicationRegistry<IPublicationRecord, IPublicationRecord>>().ImplementedBy<FakeRegistry>()); container.Register( Component.For<IRecordMapper<FakePublicationRecord>>().ImplementedBy<InMemoryRecordMapper<FakePublicationRecord>>()); container.Register(Component.For<IBlobStorage>().ImplementedBy<InMemoryBlobStorage>()); container.Register(Component.For<IMessageSerializer>().ImplementedBy<JsonMessageSerializer>()); container.Register(Component.For<FakeMessageProcessor2>().Instance(new FakeMessageProcessor2())); container.Register(Component.For<FakeMultipleMessageProcessor>().Instance(new FakeMultipleMessageProcessor())); _registry = new FakeRegistry( new InMemoryRecordMapper<FakePublicationRecord>(), new InMemoryBlobStorage(), new JsonMessageSerializer()); var locator = new WindsorServiceLocator(container); _dispatcher = new MultitaskingMessageDispatcher<IPublicationRegistry<IPublicationRecord, IPublicationRecord>>( locator, _registry); _transport = new InMemoryMessageChannel(); }
public void Setup() { BasicConfigurator.Configure(); ConfigureContainer(); _dispatcherSettings = new MessageDispatcherSettings(); _dispatcherSettings.InvalidChannel.WithDefault(_container.Resolve<IMessageChannel>("invalid")); _dispatcherSettings.InputChannel.WithDefault(_container.Resolve<IMessageChannel>("input")); _dispatcherSettings.NumberOfMessagesToDispatchPerSlice.WithDefault(20); _dispatcherSettings.DurationOfDispatchingSlice.WithDefault(new TimeSpan(0, 0, 0, 0, 500)); _dispatcherSettings.MessageProcessorTypes.WithDefault(new List<Type> { typeof(FakeCommandProcessor) }); _locator = new WindsorServiceLocator(_container); }
/// <summary> /// Instantiate the container and add all Controllers that derive from /// WindsorController to the container. Also associate the Controller /// with the WindsorContainer ControllerFactory. /// </summary> protected virtual void InitializeServiceLocator() { var container = new WindsorContainer(); // Initialize MVC application ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container)); container.RegisterControllers(typeof(HomeController).Assembly); ComponentRegistrar.AddComponentsTo(container); // Initialize WebApi container.Register(AllTypes.FromAssembly(typeof(HomeController).Assembly) .BasedOn<ApiController>() .If(r => r.Name.EndsWith("Controller")) .LifestyleTransient()); GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator), new WindsorCompositionRoot(container)); GlobalConfiguration.Configuration.DependencyResolver = new WindsorDependencyResolver(container); // Setup service locator var windsorServiceLocator = new WindsorServiceLocator(container); DomainEvents.ServiceLocator = windsorServiceLocator; ServiceLocator.SetLocatorProvider(() => windsorServiceLocator); }