/// <summary> /// Creates the child. /// </summary> /// <returns></returns> public IServiceLocator CreateChild(object tag) { var childContainer = CreateContainer(); _container.AddChildContainer(childContainer); return(new CastleWindsorServiceLocator(childContainer)); }
public IDependencyScope BeginScope() { var scope = new WindsorContainer(); container.AddChildContainer(scope); return(new WindsorDependencyScope(scope)); }
public IDependencyScope BeginScope() { IWindsorContainer childContainer = new WindsorContainer(); _container.AddChildContainer(childContainer); return(new CastleDependencyResolver(childContainer)); }
static void Process(Type type, object item, IWindsorContainer container) { using (var childContainer = new WindsorContainer()) { container.AddChildContainer(childContainer); container.Register(Component.For(type).Instance(item).OnlyNewServices()); var genericProcessorType = typeof(BaseProcessor <>); var processorType = genericProcessorType.MakeGenericType(type); try { var processor = (IProcessor)childContainer.Resolve(processorType); var result = processor.Process(); var context = childContainer.Resolve <IContext>(); childContainer.Register(Component.For <IContext>().Instance(context.Extend(result.Type, result.Id))); } catch (ComponentNotFoundException) { // some kind of logging here :) } Traverse(type, item, childContainer); } }
public IModule LoadModule(Assembly assembly) { try { var moduleInstaller = FromAssembly.Instance(assembly); var windsorContainer = new WindsorContainer(); _mainContainer.AddChildContainer(windsorContainer); windsorContainer.Install(moduleInstaller); var module = windsorContainer.Resolve <IModule>(); if (!AssemblySource.Instance.Contains(assembly)) { AssemblySource.Instance.Add(assembly); } return(module); } catch (Exception) { //TODO: good exception handling return(null); } }
/// <summary> /// 开始解析范围。 /// </summary> /// <returns> /// 依赖范围。 /// </returns> public IDependencyScope BeginScope() { var childContainer = new WindsorContainer(); container.AddChildContainer(childContainer); return(new WindsorDependencyResolver(childContainer)); }
private ViewModelsContainer CreateViewModelsContainer() { var vmContainer = new WindsorContainer(); _container.AddChildContainer(vmContainer); var instance = new ViewModelsContainer(vmContainer); vmContainer.Register(Component.For <IContainer>().Instance(instance)); return(instance); }
private IWindsorContainer CreateSubContainerConfiguredFor(Type bootstraperType) { IWindsorContainer subContainer = new WindsorContainer(); _rootContainer.AddChildContainer(subContainer); subContainer.Register( Component.For <IModuleBootstraper>().ImplementedBy(bootstraperType) ); return(subContainer); }
public static IWindsorContainer CreateChildContainerFromResult(this IWindsorContainer container, StructuralType type, long id) { var childContext = container.Resolve <IContext>().Extend(type, id); var childContainer = new WindsorContainer(); childContainer.Register(Component.For <IWindsorContainer>().Instance(childContainer)); childContainer.Register(Component.For <IContext>().Instance(childContext)); container.AddChildContainer(childContainer); return(childContainer); }
private static IWindsorContainer CreateChildContainer(IWindsorContainer parent) { var sessionComponent = Component.For<IDocumentSession>() .UsingFactoryMethod( kernel => kernel.Resolve<IDocumentStore>().OpenSession()) .LifestyleTransient(); var container = new WindsorContainer(); container.Register(sessionComponent); parent.AddChildContainer(container); return container; }
private static IWindsorContainer CreateChildContainer(IWindsorContainer container) { var childContainer = new WindsorContainer(); childContainer.Register( Component.For<IDocumentSession>() .UsingFactoryMethod(kernel => { var documentSession = kernel.Resolve<IDocumentStore>().OpenSession(); documentSession.Advanced.UseOptimisticConcurrency = true; return documentSession; }) .LifestyleTransient()); container.AddChildContainer(childContainer); return childContainer; }
/// <summary> /// Constructs a container assigning a parent container /// before starting the dependency resolution. /// </summary> /// <param name = "parent">The instance of an <see cref = "IWindsorContainer" /></param> /// <param name = "interpreter">The instance of an <see cref = "IConfigurationInterpreter" /> implementation</param> public WindsorContainer(IWindsorContainer parent, IConfigurationInterpreter interpreter) : this() { if (parent == null) { throw new ArgumentNullException("parent"); } if (interpreter == null) { throw new ArgumentNullException("interpreter"); } parent.AddChildContainer(this); interpreter.ProcessResource(interpreter.Source, kernel.ConfigurationStore, kernel); RunInstaller(); }
public void Install(IWindsorContainer container, IConfigurationStore store) { var childContainer = new WindsorContainer(); container.AddChildContainer(childContainer); var accessor = _scopeAccessor ?? typeof(WebRequestScopeAccessor); childContainer.Register( Component.For <ServiceBusController>() .LifestyleScoped(accessor) ); foreach (var assembly in _fromAssemblies) { childContainer.Register( assembly.BasedOn <IHttpController>().WithServiceSelf() .LifestyleScoped(accessor) ); } if (_useFluentValidation) { FluentValidationModelValidatorProvider .Configure(_configuration, provider => provider.ValidatorFactory = container.Resolve <IValidatorFactory>()); } _configuration.DependencyResolver = new WindsorDependencyResolver(childContainer.Kernel); ConfigureSwagger(); if (_useGlobalExceptionLogging) { var logger = container.Resolve <ILogger>(); _configuration.Services.Add(typeof(IExceptionLogger), new ServiceBusExceptionLogger(logger)); } _configuration.EnsureInitialized(); }
private TenantManager BuildTenants(IWindsorContainer container, DocumentStoreConfiguration config) { _logger.Debug("Configuring tenants"); var manager = new TenantManager(container.Kernel); container.Register(Component.For <ITenantAccessor, TenantManager>().Instance(manager)); foreach (var settings in config.TenantSettings) { _logger.DebugFormat("Adding tenant {0}", settings.TenantId); var tenant = manager.AddTenant(settings); tenant.Container.Kernel.Resolver.AddSubResolver(new CollectionResolver(tenant.Container.Kernel, true)); tenant.Container.Kernel.Resolver.AddSubResolver(new ArrayResolver(tenant.Container.Kernel, true)); tenant.Container.AddFacility <StartableFacility>(); tenant.Container.AddFacility <JarvisTypedFactoryFacility>(); container.AddChildContainer(tenant.Container); } return(manager); }
/// <summary> /// Initializes a new instance of the <see cref = "WindsorContainer" /> class. /// </summary> /// <param name = "name">The container's name.</param> /// <param name = "parent">The parent.</param> /// <param name = "interpreter">The interpreter.</param> public WindsorContainer(string name, IWindsorContainer parent, IConfigurationInterpreter interpreter) : this() { if (name == null) { throw new ArgumentNullException(nameof(name)); } if (parent == null) { throw new ArgumentNullException(nameof(parent)); } if (interpreter == null) { throw new ArgumentNullException(nameof(interpreter)); } this.name = name; parent.AddChildContainer(this); interpreter.ProcessResource(interpreter.Source, kernel.ConfigurationStore, kernel); RunInstaller(); }
public void Install(IWindsorContainer container, IConfigurationStore store) { var childContainer = new WindsorContainer(); childContainer.Register( Component.For <IControllerFactory>() .ImplementedBy <WindsorControllerFactory>() ); foreach (var assemebly in _fromAssemblies) { childContainer.Register( assemebly.BasedOn <IController>() .WithServiceSelf() .LifestyleScoped(_scopeAccessor ?? typeof(WebRequestScopeAccessor)) ); } container.AddChildContainer(childContainer); ControllerBuilder.Current.SetControllerFactory(childContainer.Resolve <IControllerFactory>()); if (_useFluentValidation) { FluentValidationModelValidatorProvider.Configure(provider => { provider.ValidatorFactory = container.Resolve <IValidatorFactory>(); }); } if (_useFeaturePaths) { ViewEngines.Engines.Clear(); ViewEngines.Engines.Add(new FeatureViewLocationRazorViewEngine()); } }
public void Install(IWindsorContainer container, IConfigurationStore store) { var childContainer = new WindsorContainer(); childContainer.Kernel.Resolver.AddSubResolver(new EnvironmentResolver()); childContainer.Kernel.Resolver.AddSubResolver( new ArrayResolver(childContainer.Kernel, true)); childContainer.Kernel.AddHandlersFilter(new RestHandlerFilter()); childContainer.Kernel.AddHandlersFilter(new BatchHandlerFilter()); childContainer.Kernel.AddHandlersFilter(new CacheHandlerFilter()); childContainer.Kernel.AddHandlersFilter(new ContravariantFilter()); childContainer.Kernel.AddHandlerSelector(new PipelineSelector()); childContainer.Register( Component.For<IMediator>().ImplementedBy<ScopedMediator>(), Component.For<EnvironmentInterceptor>().LifestyleTransient() ); foreach (var assembly in _fromAssemblies .Concat(new[] {Classes.FromThisAssembly()})) { childContainer.Register(assembly .BasedOn(typeof (IRequestHandler<,>)) .OrBasedOn(typeof (IRequestMiddleware<,>)) .OrBasedOn(typeof (IAsyncRequestHandler<,>)) .OrBasedOn(typeof (INotificationHandler<>)) .OrBasedOn(typeof (IAsyncNotificationHandler<>)) .OrBasedOn(typeof (IValidator<>)) .WithServiceBase() .LifestyleScoped() .Configure(c => { c.Proxy.Hook(new EnvironmentProxyGenerationHook()) .Interceptors<EnvironmentInterceptor>(); if (c.Implementation != null) { var requiresMatching = c.Implementation.GetInterface( typeof (IRequireGenericMatching<>).FullName); if (requiresMatching == null) return; var matcher = requiresMatching.GetGenericArguments()[0]; c.ExtendedProperties( Property.ForKey(Constants.GenericImplementationMatchingStrategy) .Eq(Activator.CreateInstance(matcher))); } })); } container.Register(Component.For<IValidatorFactory>() .ImplementedBy<WindsorValidatorFactory>() .OnlyNewServices()); container.AddChildContainer(childContainer); container.Register(Component.For<IMediator>() .Instance(childContainer.Resolve<IMediator>())); }
public Factory(IWindsorContainer outerContainer) { container = new WindsorContainer(); outerContainer.AddChildContainer(container); }
public void Install(IWindsorContainer container, IConfigurationStore store) { var childContainer = new WindsorContainer( "Improving.MediatR", new DefaultKernel(), new DefaultComponentInstaller()); childContainer.Kernel.Resolver.AddSubResolver(new EnvironmentResolver()); childContainer.Kernel.Resolver.AddSubResolver( new ArrayResolver(childContainer.Kernel, true)); childContainer.Kernel.AddHandlersFilter(new RestHandlerFilter()); childContainer.Kernel.AddHandlersFilter( new OpenGenericHandlersFilter(typeof(BatchOf <,>), typeof(BatchHandler <,>))); childContainer.Kernel.AddHandlersFilter( new OpenGenericHandlersFilter(typeof(Cached <>), typeof(CacheHandler <>))); childContainer.Kernel.AddHandlersFilter( new OpenGenericHandlersFilter(typeof(Routed <>), typeof(RouteHandler <>))); childContainer.Kernel.AddHandlersFilter(new ContravariantFilter()); childContainer.Kernel.AddHandlerSelector(new PipelineSelector()); childContainer.Register( Component.For <IMediator>().ImplementedBy <ScopedMediator>(), Component.For <EnvironmentInterceptor>().LifestyleTransient() ); childContainer.Kernel.ComponentModelCreated += Kernel_ComponentModelCreated; foreach (var assembly in _fromAssemblies .Concat(new[] { Classes.FromThisAssembly() })) { childContainer.Register(assembly .BasedOn(typeof(IRequestHandler <,>)) .OrBasedOn(typeof(IRequestMiddleware <,>)) .OrBasedOn(typeof(IAsyncRequestHandler <,>)) .OrBasedOn(typeof(INotificationHandler <>)) .OrBasedOn(typeof(IAsyncNotificationHandler <>)) .OrBasedOn(typeof(IValidator <>)) .OrBasedOn(typeof(IRouter)) .WithServiceBase() .Configure(c => { if (c.Implementation != null && typeof(IRouter).IsAssignableFrom(c.Implementation)) { return; } c.LifestyleScoped(); c.Proxy.Hook(new EnvironmentProxyGenerationHook()) .Interceptors <EnvironmentInterceptor>(); if (c.Implementation != null) { var requiresMatching = c.Implementation.GetInterface( typeof(IRequireGenericMatching <>).FullName); if (requiresMatching == null) { return; } var matcher = requiresMatching.GetGenericArguments()[0]; c.ExtendedProperties( Property.ForKey(Constants.GenericImplementationMatchingStrategy) .Eq(Activator.CreateInstance(matcher))); } })); } container.Register(Component.For <IValidatorFactory>() .ImplementedBy <WindsorValidatorFactory>() .OnlyNewServices()); container.AddChildContainer(childContainer); container.Register(Component.For <IMediator>() .Instance(childContainer.Resolve <IMediator>())); }
TenantManager BuildTenants(IWindsorContainer container, DocumentStoreConfiguration config) { _logger.Debug("Configuring tenants"); var manager = new TenantManager(container.Kernel); container.Register(Component.For<ITenantAccessor, TenantManager>().Instance(manager)); foreach (var settings in config.TenantSettings) { _logger.DebugFormat("Adding tenant {0}", settings.TenantId); var tenant = manager.AddTenant(settings); tenant.Container.Kernel.Resolver.AddSubResolver(new CollectionResolver(tenant.Container.Kernel, true)); tenant.Container.Kernel.Resolver.AddSubResolver(new ArrayResolver(tenant.Container.Kernel, true)); tenant.Container.AddFacility<StartableFacility>(); container.AddChildContainer(tenant.Container); } return manager; }