private void RegisterIMapCreators(IKernel kernel) { kernel.Register( AllTypes.Of <IMapCreator>().FromAssembly(_assembly) .WithService.FirstInterface() ); }
protected virtual void ConfigureContainer() { container.Register( AllTypes.Of <IController>() .FromAssembly(Assembly) .Configure(registration => { var name = registration.Implementation.Name; registration.Named(name.Replace("Controller", "").ToLowerInvariant()); }), AllTypes.Of <IController>() .FromAssembly(typeof(AbstractBootStrapper).Assembly) .Configure(registration => { var name = registration.Implementation.Name; registration.Named(name.Replace("Controller", "").ToLowerInvariant()); }), AllTypes.FromAssembly(Assembly) .Where(x => x.Namespace.EndsWith("Services")) .WithService.FirstInterface(), AllTypes.FromAssembly(typeof(AbstractBootStrapper).Assembly) .Where(x => x.Namespace.EndsWith("Services")) .WithService.FirstInterface() ); }
public void ConfigureIoC(string configPath) { // create a Windsor container with various component parameters established var container = new WindsorContainer(configPath); // Replaces the default IViewEngine. container.AddComponent <IViewEngine, SparkViewFactory>(); container.AddComponent <IViewActivatorFactory, WindsorViewActivator>(); // Add anything descended from IController/Controller container.Register( AllTypes.Of <IController>() .FromAssembly(typeof(Global).Assembly) .Configure(c => c.LifeStyle.Transient.Named(c.Implementation.Name.ToLowerInvariant()))); // Some more components from the sample container.AddComponent <IViewFolder, FileSystemViewFolder>(); container.AddComponent <ISampleRepository, SampleRepository>(); container.AddComponent <INavRepository, NavRepository>(); // Place this container as the dependency resolver and hook it into // the controller factory mechanism ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(container.Kernel)); ViewEngines.Engines.Add(container.Resolve <IViewEngine>()); }
private void RegisterIStartupTasks(IKernel kernel) { kernel.Register( AllTypes.Of <IStartupTask>().FromAssembly(_assembly) .WithService.FirstInterface() ); }
public void Application_OnStart() { if (container != null) { return; } container = new WindsorContainer(new XmlInterpreter()); // register our OAuth test service, to handle validating requests to protected resources etc. container.AddComponent("oauth.testService", typeof(IOAuthService), typeof(TestOAuthService)); // register service required by Rest library container.AddComponent("rest.defaultUrlProvider", typeof(DefaultUrlProvider)); // register all controllers container.Register(AllTypes.Of <Castle.MonoRail.Framework.Controller>() .FromAssembly(typeof(GlobalApplication).Assembly)); // register routes RoutingModuleEx.Engine.Add(new PatternRoute("api_id", "api/<controller>/<id>").DefaultForAction().Is("entry").DefaultForArea().Is("api") .Restrict("id").ValidInteger); RoutingModuleEx.Engine.Add(new PatternRoute("api_collection", "api/<controller>").DefaultForAction().Is("collection").DefaultForArea().Is("api")); }
private void RegisterControllers(IKernel kernel) { kernel.Register( AllTypes.Of <IController>().FromAssembly(_assembly) .If(t => !t.Name.StartsWith("T4MVC_", StringComparison.InvariantCultureIgnoreCase)) .Configure(c => c.LifeStyle.Transient) ); }
private static void RegisterJoinedFiltersInExecutingAssembly(IWindsorContainer container) { container.Register( AllTypes.Of <IJoinedFilter>() .FromAssembly(Assembly.GetExecutingAssembly()) .Configure(c => c.LifeStyle.Transient).WithService.FromInterface(typeof(IJoinedFilter)) ); }
static void RegisterWebComponents() { container.Register( AllTypes.Of <Controller>(). FromAssembly(typeof(ProductsController).Assembly) .Configure(reg => reg.Named(reg.ServiceType.Name).LifeStyle.Transient) ); }
private static void RegisterControllers(IWindsorContainer container) { container.Register( AllTypes.Of <IController>() .FromAssembly(Assembly.GetExecutingAssembly()) .Configure(c => c.LifeStyle.Transient) ); }
private static void RegisterWebComponents() { _container.Register(AllTypes.Of <SmartDispatcherController>(). FromAssembly(typeof(HomeController).Assembly)); _container.Register(AllTypes.Of <ViewComponent>() .FromAssembly(typeof(GlobalApplication).Assembly) .Configure(reg => reg.Named(reg.ServiceType.Name))); }
public static void RegisterComponents(IWindsorContainer container) { container.Register( // add all the controllers AllTypes.Of <Controller>().FromAssemblyNamed("WindsorInversionOfControl"), // this component will result in the views also being registered in the container Component.For <IViewActivatorFactory>().ImplementedBy <ViewActivator>(), // here's an example of a component used by the views. see the View class. Component.For <INavProvider>().ImplementedBy <NavProvider>()); }
public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register( AllTypes.Of <IController>().FromAssembly(Assembly.GetExecutingAssembly()).Configure(c => c.LifestyleTransient())); container.Register(AllTypes.Pick().FromAssemblyNamed("Marketplace.Interview.Business") .Configure(c => c.LifestyleTransient()) .If(t => t.FindInterfaces((t1, o) => t1.Name == "IWorkflow", null).Length > 0) .BasedOn(typeof(IWorkflow <,>)).WithService.FromInterface(typeof(IWorkflow <,>))); }
private static void RegisterMvcComponents(IWindsorContainer container) { container.Register(AllTypes.Of <IController>() .FromAssembly(Assembly.GetExecutingAssembly()) .Configure(c => c.LifeStyle.Transient) ); // Register MVC sitemap provider container.Register(Component.For <IMvcSitemapProvider>() .ImplementedBy <MvcSitemapProvider>() ); }
protected override IServiceLocator CreateServiceLocator() { IWindsorContainer container = new WindsorContainer() .Register( AllTypes.Of <ILogger>() .FromAssembly(typeof(ILogger).Assembly) .WithService.FirstInterface() ); return(new WindsorServiceLocator(container)); }
static void RegisterWebComponents() { container.Register( AllTypes.Of <SmartDispatcherController>(). FromAssembly(typeof(TestController).Assembly), AllTypes.Of <IFilter>(). FromAssembly(typeof(TestController).Assembly), AllTypes.Of <ViewComponent>().FromAssembly(typeof(Global).Assembly) .Configure(reg => reg.Named(reg.ServiceType.Name)) ); }
public static void Install() { Container = new WindsorContainer(); Container.Register(Component.For <IWindsorContainer>().Instance(Container).LifestyleSingleton()); Container.Register(AllTypes.Of <System.Web.Mvc.IController>().FromAssembly(System.Reflection.Assembly.GetExecutingAssembly()).LifestyleTransient()); ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(Container)); Container.Register(Component.For <IServiceLocator>().Instance(ServiceLocator.Current).LifestyleSingleton()); System.Web.Mvc.ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(Container)); }
public void Init(IWindsorContainer container) { if (container == null) { throw new ArgumentNullException("container"); } container.Register( AllTypes.Of <IRegistration>().FromAssembly(Assembly.GetExecutingAssembly()) .WithService.FirstInterface() ); container.Register(container.ResolveAll <IRegistration>()); }
public WindsorControllerFactory() { container = new WindsorContainer( new XmlInterpreter( new ConfigResource("castleWindsor") )); container.Register( AllTypes.Of <IController>() .FromAssembly(Assembly.GetExecutingAssembly()) .Configure(component => component.LifeStyle.Transient .Named(component.Implementation.Name) )); }
public void LocatePackages() { // NOTE - this could be a place to rely on a package locating service // rather than code in the discovery strategy var searchPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AppDomain.CurrentDomain.RelativeSearchPath); foreach (var assemblyName in Directory.GetFiles(searchPath, "*.dll").Select(path => Path.GetFileNameWithoutExtension(path))) { _kernel .Register(AllTypes .Of <IWebPackage>() .FromAssemblyNamed(assemblyName) .WithService.FromInterface(typeof(IWebPackage))); } }
protected void Application_Start() { Bootstrapper.Install(); PluginBootstrapper.Initialize(); Injector.Inject(); var container = ServiceLocator.Current.GetInstance <Castle.Windsor.IWindsorContainer>(); container.Register(AllTypes.Of <IController>().FromAssembly(Assembly.GetExecutingAssembly()) .LifestyleTransient()); AreaRegistration.RegisterAllAreas(); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
public void Install(IWindsorContainer container) { container.AddFacility <EventPublisherFacility>(); container.AddFacility <StartableFacility>(); container.AddFacility <DockingFacility>(); container.AddFacility <MenuFacility>(); container.AddComponent("applicationShell", typeof(IApplicationShell), typeof(ApplicationShell)); container.AddComponent("presenter.factory", typeof(IPresenterFactory), typeof(PresenterFactory)); container.Register( Component.For <IImageSource>().ImplementedBy <ResourceManagerImageSource>().Named("imageSource.res")); container.Register( Component.For <IImageFactory>() .ImplementedBy <ImageFactory>() .ServiceOverrides( ServiceOverride.ForKey("sources").Eq <IImageSource>("imageSource.res"))); // todo: refactor to register all views and presenters declaratively. container.Register( Component.For <IOutputView>().ImplementedBy <OutputView>(), Component.For <IOutputPresenter>().ImplementedBy <OutputPresenter>(), Component.For <IProjectExplorerView>().ImplementedBy <ProjectExplorerView>(), Component.For <IProjectExplorerPresenter>().ImplementedBy <ProjectExplorerPresenter>(), Component.For <IPropertyGridView>().ImplementedBy <PropertyGridView>(), Component.For <IPropertyGridPresenter>().ImplementedBy <PropertyGridPresenter>(), Component.For <IToolBoxView>().ImplementedBy <ToolBoxView>(), Component.For <IToolBoxPresenter>().ImplementedBy <ToolBoxPresenter>()); container.Register( Component .For <IMenuPresenter>() .ImplementedBy <MenuStripPresenter>() .Parameters( Parameter .ForKey("menu") .Eq("${" + MainMenuToolStripKey + "}"))); container.Register(AllTypes.Of <AbstractCommand>().FromAssembly(typeof(AbstractCommand).Assembly)); container.Register( Component.For <DockedWindowsMenuModel>()); }
public void RegisterComponents(IWindsorContainer container) { container .Register(Component .For <IControllerFactory>() .ImplementedBy <ModularControllerFactory>() .LifeStyle.Singleton) .Register(Component .For <IWebPackageManager>() .ImplementedBy <WebPackageManager>() .LifeStyle.Transient) .Register(AllTypes .Of <IController>() .FromAssembly(typeof(Application).Assembly) .Configure(component => component .Named(component.ServiceType.Name.ToLowerInvariant()) .LifeStyle.Transient)); }
void LoadTypesByScan() { string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var files = from f in Directory.GetFiles(assemblyPath) where f.StartsWith("MassTransit.Transports.") select f; var types = new List <Type>(); foreach (var file in files) { Kernel.Register(AllTypes.Of <IEndpoint>() .FromAssemblyNamed(file).Configure(c => types.Add(c.Implementation))); } RegisterEndpointFactory(x => { types.Each(x.RegisterTransport); _configurationAction(x); }); }
private static void RegisterValidatorComponents(IWindsorContainer container) { container.Register(Component.For <IBrowserValidatorProvider>() .ImplementedBy <JQueryValidator>() ); container.Register(Component.For <ILocalizedValidatorRegistry>() .ImplementedBy <CachedLocalizedValidatorRegistry>() ); // Register specific generic castle model validator container.Register(Component.For(typeof(IModelValidator <>)) .ImplementedBy(typeof(CastleModelValidator <>)) .LifeStyle.Transient ); // Register all model validators. container.Register(AllTypes.Of <IModelValidator>() .FromAssembly(typeof(IModelValidator).Assembly) .Configure(c => c.LifeStyle.Transient)); container.Register(Component.For <BrowserValidationEngine>()); container.Kernel.AddComponentInstance("validationresources", Resources.Cuyahoga.ValidationMessages.ResourceManager); // Set validation engine to accessor. ValidationEngineAccessor.Current.SetValidationEngine(container.Resolve <BrowserValidationEngine>()); }
public ContainerControllerFactory() { container = new WindsorContainer(); container.Register( AllTypes.Of(typeof(IController)) .FromAssembly(typeof(HomeController).Assembly) ); container.Register( AllTypes .Pick().FromAssembly(typeof(ProductService).Assembly) .If(s => s.Name.EndsWith("Service")) .WithService.FirstInterface() ); container.Register( AllTypes .Pick().FromAssembly(typeof(ProductRepository).Assembly) .If(s => s.Name.EndsWith("Repository")) .WithService.FirstInterface() ); container.Register(Component.For <IDataContext>().ImplementedBy <MyOrmDataContext>()); }
public virtual void RegisterComponents() { //presenters and views _container.Register ( Component.For <IDataEditorView>().ImplementedBy <DataEditor>().LifeStyle.Transient, Component.For <IDataSetProvider>().ImplementedBy <DataSetProvider>().LifeStyle.Transient, Component.For <DataEditorPresenter>().LifeStyle.Transient, Component.For <IFileDialogCreator>().ImplementedBy <FileDialogCreator>().LifeStyle.Transient, Component.For <IMessageCreator>().ImplementedBy <MessageCreator>().LifeStyle.Transient, Component.For <IDataSetFromDatabaseView>().ImplementedBy <DataSetFromDatabase>().LifeStyle.Transient, Component.For <DataSetFromDatabasePresenter>().LifeStyle.Singleton, Component.For <IApplicationController>().ImplementedBy <ApplicationController>(), Component.For <IEventAggregator>().ImplementedBy <EventAggregator>() ); //settings persistennce and retrieval _container.Register ( Component.For <IUserSettingsRepository>().ImplementedBy <UserSettingsRepository>() .Parameters(Parameter.ForKey("configFileType").Eq(UserSettingsRepository.Config.PrivateFile.ToString())) .Parameters(Parameter.ForKey("applicationName").Eq("NDbUnitEditor")), Component.For <IProjectRepository>().ImplementedBy <ProjectRepository>().LifeStyle.Transient ); _container.Register( AllTypes.Of <ICommand>().FromAssembly(Assembly.GetExecutingAssembly())); //NDbUnit interaction _container.Register ( Component.For <NDbUnitFacade>().LifeStyle.Transient ); IoC.Initialize(_container); }
public static void Register(IWindsorContainer container) { container.Register( AllTypes.Of <DynamicActionDescriptor>().FromAssembly(typeof(DynamicController).Assembly) ); container.Register( AllTypes.Of <IFindAction>().FromAssembly(typeof(DynamicController).Assembly) ); container.Register( Component.For <IDynamicQuery>().ImplementedBy <DynamicQuery>() ); container.Register( Component.For <ServicesRegistry>().ImplementedBy <DynamicServicesRegistry>().LifeStyle.Singleton ); container.Register( Component.For <ISakurityOffica>().ImplementedBy <SakurityOffica>().LifeStyle.Singleton ); container.Register( Component.For <IDynamicStage>().ImplementedBy <SakurityStage>().LifeStyle.Transient ); container.Register( Component.For <DomainInvoker>().LifeStyle.Transient ); container.Register( Component.For <SortingStage>().LifeStyle.Transient ); container.Register( Component.For <FilteringStage>().LifeStyle.Transient ); container.Register( Component.For <PaginationStage>().LifeStyle.Transient ); container.Register( Component.For <InjectMenuResultFilter>().LifeStyle.Transient ); }
public void ActivateModule(ModuleType moduleType) { //only one thread at a time System.Threading.Monitor.Enter(lockObject); string assemblyQualifiedName = moduleType.ClassName + ", " + moduleType.AssemblyName; if (log.IsDebugEnabled) { log.DebugFormat("Loading module {0}.", assemblyQualifiedName); } // First, try to get the CLR module type Type moduleTypeType = Type.GetType(assemblyQualifiedName); if (moduleTypeType == null) { throw new Exception("Could not find module: " + assemblyQualifiedName); } try { // double check, if we should continue if (this._kernel.HasComponent(moduleTypeType)) { // Module is already registered if (log.IsDebugEnabled) { log.DebugFormat("The module with type {0} is already registered in the container.", moduleTypeType.ToString()); } return; } // First, register optional module services that the module might depend on. foreach (ModuleService moduleService in moduleType.ModuleServices) { Type serviceType = Type.GetType(moduleService.ServiceType); Type classType = Type.GetType(moduleService.ClassType); if (log.IsDebugEnabled) { log.DebugFormat("Loading module service {0}, (1).", moduleService.ServiceKey, moduleService.ClassType); } LifestyleType lifestyle = LifestyleType.Singleton; if (moduleService.Lifestyle != null) { try { lifestyle = (LifestyleType)Enum.Parse(typeof(LifestyleType), moduleService.Lifestyle); } catch (ArgumentException ex) { throw new Exception(String.Format("Unable to load module service {0} with invalid lifestyle {1}." , moduleService.ServiceKey, moduleService.Lifestyle), ex); } } this._kernel.AddComponent(moduleService.ServiceKey, serviceType, classType, lifestyle); } //Register the module string moduleTypeKey = "module." + moduleTypeType.FullName; this._kernel.AddComponent(moduleTypeKey, moduleTypeType); // no lifestyle because ModuleBase has the Transient attribute. //Configure NHibernate mappings and make sure we haven't already added this assembly to the NHibernate config if (typeof(INHibernateModule).IsAssignableFrom(moduleTypeType) && ((HttpContext.Current.Application[moduleType.AssemblyName]) == null)) { if (log.IsDebugEnabled) { log.DebugFormat("Adding module assembly {0} to the NHibernate mappings.", moduleTypeType.Assembly.ToString()); } this._sessionFactoryHelper.AddAssembly(moduleTypeType.Assembly); //set application variable to remember the configurated assemblies HttpContext.Current.Application.Lock(); HttpContext.Current.Application[moduleType.AssemblyName] = moduleType.AssemblyName; HttpContext.Current.Application.UnLock(); } if (typeof(IMvcModule).IsAssignableFrom(moduleTypeType)) { IMvcModule module = this._kernel.Resolve <IMvcModule>(moduleTypeKey); // Add routes to the routetable if the module supports MVC module.RegisterRoutes(RouteTable.Routes); // Register module controllers this._kernel.Register(AllTypes .Of(typeof(IController)) .FromAssembly(moduleTypeType.Assembly) .Configure(c => c.LifeStyle.Transient)); } // Register model validators for modules this._kernel.Register(AllTypes .Of <IModelValidator>() .FromAssembly(moduleTypeType.Assembly) .Configure(c => c.LifeStyle.Transient)); } finally { System.Threading.Monitor.Exit(lockObject); } } //end method
/// <summary> /// Registers all the services of type <typeparamref name="Interface"/> into the container. /// </summary> /// <typeparam name="Interface"></typeparam> public void RegisterAll <Interface>() { //TODO: see if this works AllTypes.Of <Interface>(); }
public WindsorDependencyResolver(ICommandArgs commandArgs) { innerContainer = new WindsorContainer(); if (commandArgs != null) { innerContainer.Kernel.AddComponentInstance <ICommandArgs>(typeof(ICommandArgs), commandArgs); } innerContainer.Kernel.Resolver.AddSubResolver(new EnumerableResolver(innerContainer.Kernel)); innerContainer.Register( Component.For <IBuildConfigReader>() .Named("boo") .ImplementedBy <BooBuildConfigReader>() .LifeStyle.Transient ); innerContainer.Register( Component.For <SVNSourceControl>() .Named("Svn") .LifeStyle.Transient ); innerContainer.Register( Component.For <GitSourceControl>() .Named("Git") .LifeStyle.Transient ); innerContainer.Register( Component.For <MercurialSourceControl>() .Named("Hg") .LifeStyle.Transient ); innerContainer.Register( Component.For <IPackageCommand>() .Named("install") .ImplementedBy <PackageBuilder>() .LifeStyle.Transient ); innerContainer.Register( Component.For <IGet>() .Named("get") .ImplementedBy <Get>() .LifeStyle.Transient ); innerContainer.Register( Component.For <IFileSystemProvider>() .Named("filesystemprovider") .ImplementedBy <FileSystemProvider>() .LifeStyle.Transient ); innerContainer.Register( Component.For <IProcessFactory>() .Named("processfactory") .ImplementedBy <DiagnosticsProcessFactory>() .LifeStyle.Transient ); innerContainer.Register( Component.For <SourceControl>() .ImplementedBy <GitSourceControl>() .Parameters(Parameter.ForKey("url").Eq(MetaDataSynchroniser.PackageTreeUri)) .LifeStyle.Transient ); innerContainer.Register( Component.For <IMetaDataSynchroniser>() .ImplementedBy <MetaDataSynchroniser>() .LifeStyle.Transient ); innerContainer.Register( Component.For <IPackageTree>() .ImplementedBy <PackageTree>() .LifeStyle.Transient ); innerContainer.Register( Component.For <IEnvironmentVariable>() .ImplementedBy <EnvironmentVariable>() .LifeStyle.Transient ); innerContainer.Register( Component.For <IShellRunner>() .ImplementedBy <CommandLineRunner>() .LifeStyle.Transient ); innerContainer.Register( Component.For <IDependencyDispatcher>() .ImplementedBy <DependencyDispatcher>() .LifeStyle.Transient, Component.For <IDependentUpdaterExecutor>() .ImplementedBy <DependentUpdaterExecutor>() .LifeStyle.Transient, AllTypes.Of <IDependentUpdater>().FromAssembly(Assembly.GetExecutingAssembly()) .WithService.FirstInterface().Configure(config => config.LifeStyle.Transient) ); }