private static void InitContainer(Assembly applicationAssembly) { Container.Install(FromAssembly.Instance(applicationAssembly)); DependencyResolver.SetResolver(new WindsorDependencyResolver(Container)); GlobalConfiguration.Configuration.DependencyResolver = new WindsorDependencyResolver(Container); }
private void CallAssemblyInstaller([NotNull] IWindsorContainer container, [NotNull] Assembly assembly) { string name = assembly.ManifestModule.Name; Console.WriteLine("{0} - Checking...", name); if (IsIgnoredAssemblyName(name)) { Console.WriteLine("{0} - Ignored!", name); return; } if (!name.StartsWith("Selkie.", StringComparison.Ordinal) && !name.StartsWith("Evaluation.", StringComparison.Ordinal)) { return; } Console.WriteLine("{0} - Processing...", name); container.Install(FromAssembly.Instance(assembly)); }
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); } }
public IModule Load(Assembly assembly) { try { var moduleInstaller = FromAssembly.Instance(assembly); var modulecontainer = new WindsorContainer(); _container.AddChildContainer(modulecontainer); modulecontainer.Install(moduleInstaller); var module = modulecontainer.Resolve <IModule>(); //If ViewModel can't find View, we need to add loaded assemblies if (!AssemblySource.Instance.Contains(assembly)) { AssemblySource.Instance.Add(assembly); } return(module); } catch (Exception exception) { _logger.Error(exception); return(null); } }
private IWindsorContainer SetInstallers() { var container = new WindsorContainer(); container.Register(Component.For <IWindsorContainer>().Instance(container).LifestyleSingleton()); container.Install(FromAssembly.Instance(Assembly.GetExecutingAssembly())); return(container); }
/// <summary> /// 扫描自身程序集并自动注册组件 /// </summary> public void Register(Assembly asm) { if (Container == null) { new WindsorContainer(); } Container.Install(FromAssembly.Instance(asm)); }
/// <summary> /// 注册程序集。 /// </summary> /// <param name="assembly">程序集</param> public void RegisterAssemblyByConvention(Assembly assembly) { IConventionalRegistrationContext context = new ConventionalRegistrationContext(assembly, this); foreach (var registrar in _conventionalRegistrars) { registrar.RegisterAssembly(context); } IocContainer.Install(FromAssembly.Instance(assembly)); }
public virtual void Application_Start() { IWindsorInstaller windsorInstaller = FromAssembly.Instance(Assembly.GetCallingAssembly()); _container.Install(windsorInstaller); System.Web.Mvc.DependencyResolver.SetResolver(new WindsorDependencyResolver(System.Web.Mvc.DependencyResolver.Current, _container.Kernel)); GlobalFilters.Filters.Add(new NHibernateSessionPerRequestFilter()); }
public static void Start() { lock (LockObj) { if (!_started) { Logger.Debug("Bootstrapping..."); Container.Instance.Install(FromAssembly.Instance(Assembly.GetExecutingAssembly())); _started = true; } } }
internal static void InitializeContainer() { var windsorContainer = new WindsorContainer(); var widgetAssemblies = ControllerContainerResolver.RetrieveAssemblies(); foreach (var assembly in widgetAssemblies) { windsorContainer.Install(FromAssembly.Instance(assembly)); } container = windsorContainer; }
public void Execute() { Container = new WindsorContainer(); Container.Install(FromAssembly.Instance(Assembly.GetExecutingAssembly())); var client = Container.Resolve <IClockService>(); client.Connect(); Console.Read(); client.Disconnect(); }
/// <summary> /// 通过协议注册器注册给定程序集的类型. See <see cref="AddConventionalRegistrar"/> method. /// </summary> /// <param name="assembly">注册程序集</param> /// <param name="config">其他配置信息</param> public void RegisterAssemblyByConvention(Assembly assembly, ConventionalRegistrationConfig config) { var context = new ConventionalRegistrationContext(assembly, this, config); foreach (var registerer in _conventionalRegistrars) { registerer.RegisterAssembly(context); } if (config.InstallInstallers) { IocContainer.Install(FromAssembly.Instance(assembly)); } }
public void RegistrarAssemblyPorConvencao(Assembly assembly, ConfiguracaoConvencionalRegistro config) { var contexto = new ContextoConvencionalRegistro(assembly, this, config); foreach (var registrador in convencaoDeRegistros) { registrador.RegistrarAssembly(contexto); } if (config.InstalarInstaladores) { ContainerIoC.Install(FromAssembly.Instance(assembly)); } }
public static IWindsorContainer AddTaskScheduler(this IWindsorContainer container, TaskSchedulerOptions options = null) { options = options ?? TaskSchedulerOptions.Default; container.Register( Component .For <TaskSchedulerOptions>() .Instance(options) .LifestyleSingleton()); container.Install(FromAssembly.Instance(Assembly.GetExecutingAssembly())); return(container); }
public void Install([NotNull] IWindsorContainer container, [NotNull] IConfigurationStore store) { RegisterWpfComponents(container); IEnumerable <Assembly> allAssemblies = AllAssembly().OrderBy(x => x.FullName).ToArray(); DisplayAssemblies(allAssemblies); Assembly selkieWindsor = GetSelkieAssembly("Selkie.Windsor.dll", allAssemblies); // need to install first, other depend on it Assembly easyNetQ = GetSelkieAssembly("Selkie.EasyNetQ.dll", allAssemblies); // need to install second, other depend on it container.Install(FromAssembly.Instance(selkieWindsor)); container.Install(FromAssembly.Instance(easyNetQ)); foreach (Assembly assembly in allAssemblies) { CallAssemblyInstaller(container, assembly); } // todo all this manual registration below will disappears when using seperate DLLs and installers for Models, ViewModels... // register Models container.Register(Classes.FromThisAssembly() .BasedOn <IModel>() .WithServiceFromInterface(typeof(IModel)) .Configure(c => c.LifeStyle.Is(LifestyleType.Transient))); // register ViewModels container.Register(Classes.FromThisAssembly() .BasedOn <IViewModel>() .WithServiceFromInterface(typeof(IViewModel)) .Configure(c => c.LifeStyle.Is(LifestyleType.Transient))); // register Views container.Register(Classes.FromThisAssembly() .BasedOn <IView>() .WithServiceFromInterface(typeof(IView)) .Configure(c => c.LifeStyle.Is(LifestyleType.Transient))); // register others container.Register(Component.For <ICommandManager>() .ImplementedBy <CommandManager>()); container.Register(Component.For <ISettingsManager>() .ImplementedBy <SettingsManager>()); }
static void Main(string[] args) { //Install IocManager.Instance.IocContainer.Install( //1.安装器 new ShawnWongInstaller(), //方式二:顾名思义 //1:反射需要注册的程序集 FromAssembly.Instance(typeof(IPerson).Assembly) //2:按名字 //3 ); //规约注册 IocManager.Instance.IocContainer.Register( Classes.FromAssembly(typeof(IPerson).Assembly) .Where(p => p.Name.EndsWith("Repository")) .WithService.AllInterfaces().LifestyleTransient()); var r = IocManager.Instance.Resolve <IShopping>().shopshoes(180); var t = IocManager.Instance.Resolve <IPerson>().MyName("sss"); var e = IocManager.Instance.Resolve <IPerson>().yourname("rrr"); var y = IocManager.Instance.Resolve <ITestRepository>().testConservtion(6); //ShoppingInterceptor inte=new ShoppingInterceptor(100); //ProxyGenerator getGenerator=new ProxyGenerator(); //var t = getGenerator.CreateClassProxy<Shopping>(inte); //t.shopshoes(120); //IocManager.Instance.IocContainer.Register( // Component.For(typeof(IShopping)) // .ImplementedBy(typeof(Shopping)) //); //IocManager.Instance.Resolve<IShopping>().shopshoes(180); Console.ReadLine(); }
public void Install() { this.RegisterCommonServices(); var suffix = $"*.{InstallAssemblySuffix}.dll"; var assemblies = AssemblyScanner .ScanForAssemblies(suffix) .Select(a => a.Assembly) .ToList(); foreach (var assembly in assemblies) { this.Container.Install(FromAssembly.Instance(assembly, new ExtendedInstallerFactory(CommonInstallerName))); } }
public void Init() { IWindsorContainer IocContainer = new WindsorContainer(); IocContainer.Register( Classes.FromAssembly(Assembly.GetExecutingAssembly()) .IncludeNonPublicTypes() .BasedOn <ITransientDependency>() .WithService.Self() .WithService.DefaultInterfaces() .LifestyleTransient() ); IocContainer.Install(FromAssembly.Instance(Assembly.GetExecutingAssembly())); IocContainer.AddFacility <LoggingFacility>(f => f.UseLog4Net().WithConfig("log4net.config")); }
/// <summary> /// 根据约定注册程序集 /// </summary> /// <param name="assembly"></param> /// <param name="config"></param> public void RegisterAssemblyByConvention(Assembly assembly, ConventionalRegistrationConfig config) { var context = new ConventionalRegistrationContext(assembly, this, config); var windsorInstaller = FromAssembly.Instance(assembly); foreach (var registerer in _conventionalRegistrars) { registerer.RegisterAssembly(context); } if (config.InstallInstallers && windsorInstaller != null) { Container.Install(windsorInstaller); } _isRegistrarWindsorInstaller.Add(assembly, windsorInstaller); }
public void TestFromAssemblyInstance() { List <Type> types = new List <Type> { typeof(object), typeof(TestInstaller) }; Mock <AssemblyWrapper> assemblyMock = new Mock <AssemblyWrapper>(); assemblyMock.Setup(a => a.GetTypes()).Returns(types.ToArray); IIocContainer iocContainer = new IocContainer(); iocContainer.Install(FromAssembly.Instance(assemblyMock.Object)); }
public static void Configure(params Assembly[] assembliesOfTypesToRegister) { IWindsorContainer container = new WindsorContainer(); DependencyResolver.SetResolver(new WindsorDependencyResolver(container)); container.Install(FromAssembly.InDirectory(new AssemblyFilter(AppDomain.CurrentDomain.BaseDirectory))); container.Install(FromAssembly.InDirectory(new AssemblyFilter(AppDomain.CurrentDomain.BaseDirectory + "\\bin"))); foreach (Assembly assembly in assembliesOfTypesToRegister) { container.Install(FromAssembly.Instance(assembly)); } RegisterTypes(container); }
/// <summary> /// Register components for IoC container. /// Installer class is configured in web.config. For customization project, developing new installer /// </summary> public void RegisterComponents() { if (!IsInstalled) { if (InstallerAssemblyName == string.Empty) { this.Install(FromAssembly.This()); //Register installer in this assembly } else { Assembly asm = Assembly.LoadFile(InstallerAssemblyName); this.Install(FromAssembly.Instance(asm)); } IsInstalled = true; } }
private static WindsorContainer CreateContainer(Assembly applicationAssembly) { var container = new WindsorContainer(); container.AddFacility <TypedFactoryFacility>(); container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel, allowEmptyArray: true)); container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel, allowEmptyCollections: true)); container.Kernel.ComponentModelBuilder.AddContributor(new PhoneClientComponentModelContributor()); container.Register(Component.For <IWindsorContainer>().Instance(container)); container.Install(FromAssembly.Instance(applicationAssembly)); return(container); }
public void Test() { var a = Assembly.GetExecutingAssembly(); var b = typeof(Class1).Assembly; IWindsorContainer IocContainer = new WindsorContainer(); IocContainer.Register( Classes.FromAssembly(typeof(RoleApplication).Assembly) .IncludeNonPublicTypes() .BasedOn <ITransientDependency>() .WithService.Self() .WithService.DefaultInterfaces() .LifestyleTransient() ); IocContainer.Install(FromAssembly.Instance(typeof(RoleApplication).Assembly)); IUserApplication user = IocContainer.Resolve <IUserApplication>(); user.Save(); }
private static void Main() { IWindsorContainer container = new WindsorContainer(); Assembly executingAssembly = Assembly.GetExecutingAssembly(); container.Install(FromAssembly.Instance(executingAssembly)); var client = container.Resolve <ISelkieManagementClient>(); client.PurgeQueueForServiceAndMessage("Name", "MessageName"); var serviceConsole = container.Resolve <IServiceConsole>(); serviceConsole.Start(false); container.Dispose(); Console.ReadLine(); }
// ReSharper disable once VirtualMemberNeverOverridden.Global public virtual IWindsorInstaller GetWindsorInstaller() { Assembly assembly = this.GetAssembly(); var compositeInstaller = new CompositeInstaller(); if (this.SearchWindsorInstallersInThisAssembly) { IWindsorInstaller assemblySpecificInstallers = FromAssembly.Instance(assembly); compositeInstaller.Add(assemblySpecificInstallers); } if (this.PopulateComponentsAutomatically) { var componentInstaller = new ComponentInstaller(this); compositeInstaller.Add(componentInstaller); } return(compositeInstaller); }
/// <summary> /// Creates the Castle Windsor container using the "castle" section from the application configuration file (if it exists), /// calls the provided <paramref name="onExecutingInstallers"/> delegate, and then executes all the "installers" found in the /// specified assembly (if supplied) to register all components with the container. /// </summary> /// <param name="onExecutingInstallers">An action delegate to be executed after the container is created, but before any of /// the installers are executed. Provides an opportunity for the caller to install facilities, subresolvers, etc. prior /// to the full registration of components.</param> /// <param name="assemblyToScanForAdditionalInstallers">The assembly to scan for additional installers.</param> /// <param name="allowableEmptyCollectionItemTypes"></param> /// <returns>The newly initialized container.</returns> public IWindsorContainer CreateContainer( Action <IWindsorContainer> onExecutingInstallers, Assembly assemblyToScanForAdditionalInstallers = null) { var castleSection = configSectionProvider.GetSection("castle"); // Determine if the "castle" section of the web.config file exists bool hasXmlConfig = !(castleSection == null || string.IsNullOrWhiteSpace( ((ConfigurationSection)castleSection) .SectionInformation.GetRawXml())); // Create the container (and initialize from config file section, if present) var container = hasXmlConfig ? new WindsorContainerEx(new XmlInterpreter()) : new WindsorContainerEx(); // Add collection support container.AddSupportForEmptyCollections(); if (onExecutingInstallers != null) { onExecutingInstallers(container); } // Install other components into the container, using installers var allConfiguredInstallers = GetConfiguredInstallers(); // logger.Debug("Installing " + allConfiguredInstallers.Length + " installers from config file."); container.Install(allConfiguredInstallers); // Scan for other installers in the assembly, if provided // TODO: We will want to remove this functionality altogether once all uses of this behavior are removed if (assemblyToScanForAdditionalInstallers != null) { container.Install(FromAssembly.Instance(assemblyToScanForAdditionalInstallers, new CustomInstallerFactory(allConfiguredInstallers))); } return(container); }
public void Install([NotNull] IWindsorContainer container, [NotNull] IConfigurationStore store) { IEnumerable <Assembly> allAssemblies = AllAssembly().OrderBy(x => x.FullName).ToArray(); DisplayAssemblies(allAssemblies); Assembly selkieWindsor = GetSelkieAssembly("Selkie.Windsor.dll", allAssemblies); // need to install first, other depend on it container.Install(FromAssembly.Instance(selkieWindsor)); foreach (Assembly assembly in allAssemblies) { CallAssemblyInstaller(container, assembly); } RegisterViewModelComponents(container); RegisterServiceComponents(container); RegisterCalibunMicroComponents(container); }
private static void InitializeExternalApiImplementations(IWindsorContainer container) { var loadedAssemblies = new List <Assembly>(); string implPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin\\impl"); if (!Directory.Exists(implPath)) { return; } foreach (var file in Directory.GetFiles(implPath)) { if (file.Contains("API.External") && file.EndsWith(".dll")) { loadedAssemblies.Add(Assembly.LoadFrom(file)); } } foreach (var loadedAssembly in loadedAssemblies) { container.Install(FromAssembly.Instance(loadedAssembly)); } }
/// <inheritdoc /> public void Install(IEnumerable <Assembly> assemblies) { assemblies.ForEach(assembly => _container.Install(FromAssembly.Instance(assembly))); }