public void Install_from_assembly_by_directory_obeys_name_condition()
        {
            var location     = AppContext.BaseDirectory;
            var byNameCalled = false;

            Container.Install(FromAssembly.InDirectory(new AssemblyFilter(location).FilterByName(a =>
            {
                byNameCalled = true;
                return(false);
            })));

            Assert.IsTrue(byNameCalled);
            Assert.IsFalse(Container.Kernel.HasComponent("Customer-by-CustomerInstaller"));
        }
Пример #2
0
        /// <summary>
        /// Registers types of given assembly by all conventional registrars. See <see cref="AddConventionalRegistrar"/> method.
        /// 通过约定注册,注册给定程序集的类型,查看方法 <see cref="AddConventionalRegistrar"/>
        /// </summary>
        /// <param name="assembly">Assembly to register / 要注册的程序集</param>
        /// <param name="config">Additional configuration / 额外的配置</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));
            }
        }
Пример #3
0
        public void Install_from_assembly_by_directory_executes_assembly_condition()
        {
            var location = AppDomain.CurrentDomain.BaseDirectory;
            var called   = false;

            container.Install(FromAssembly.InDirectory(new AssemblyFilter(location).FilterByAssembly(a =>
            {
                called = true;
                return(true);
            })));

            Assert.IsTrue(called);
            Assert.IsTrue(container.Kernel.HasComponent("Customer-by-CustomerInstaller"));
        }
Пример #4
0
        public void Install_from_assembly_by_directory_with_mscorlib_key_does_not_install()
        {
            var location = AppDomain.CurrentDomain.BaseDirectory;

            var publicKeyToken = GetType().Assembly.GetName().GetPublicKeyToken();

            if (publicKeyToken == null || publicKeyToken.Length == 0)
            {
                Assert.Ignore("Assembly is not signed so no way to test this.");
            }

            container.Install(FromAssembly.InDirectory(new AssemblyFilter(location).WithKeyToken <object>()));
            Assert.IsFalse(container.Kernel.HasComponent("Customer-by-CustomerInstaller"));
        }
Пример #5
0
        public App()
        {
            _container = new WindsorContainer();
            _container.Install(FromAssembly.This());

            _trayIcon = _container.Resolve <ITrayIcon>();
            _logger   = _container.Resolve <ILogger>();


            SquirrelAwareApp.HandleEvents(
                onInitialInstall: InitialInstall,
                onAppUpdate: AppUpdate,
                onAppUninstall: AppUninstall);
        }
Пример #6
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            DispatcherUnhandledException += OnDispatcherUnhandledException;

            _container = new WindsorContainer();

            var propInjector = _container.Kernel.ComponentModelBuilder
                               .Contributors
                               .OfType <PropertiesDependenciesModelInspector>()
                               .Single();

            _container.Kernel.ComponentModelBuilder.RemoveContributor(propInjector);

            _container.AddFacility <TypedFactoryFacility>();
            _container.Install(FromAssembly.InThisApplication());

            Mapper.Configuration.ConstructServicesUsing(_container.Resolve);

            Mapper.CreateMap <ItemFilterBlockGroup, ItemFilterBlockGroupViewModel>()
            .ForMember(destination => destination.ChildGroups, options => options.ResolveUsing(
                           delegate(ResolutionResult resolutionResult)
            {
                var context      = resolutionResult.Context;
                var showAdvanced = (bool)context.Options.Items["showAdvanced"];
                var group        = (ItemFilterBlockGroup)context.SourceValue;
                if (showAdvanced)
                {
                    return(group.ChildGroups);
                }
                else
                {
                    return(group.ChildGroups.Where(c => c.Advanced == false));
                }
            }))
            .ForMember(dest => dest.SourceBlockGroup,
                       opts => opts.MapFrom(from => from))
            .ForMember(dest => dest.IsExpanded,
                       opts => opts.UseValue(false));

            Mapper.CreateMap <Theme, IThemeEditorViewModel>().ConstructUsingServiceLocator();
            Mapper.CreateMap <ThemeComponent, ThemeComponentViewModel>().ReverseMap();
            Mapper.CreateMap <IThemeEditorViewModel, Theme>();

            Mapper.AssertConfigurationIsValid();

            var mainWindow = _container.Resolve <IMainWindow>();

            mainWindow.Show();
        }
Пример #7
0
        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>());
        }
Пример #8
0
        public static void Startup()
        {
#pragma warning disable 618
            // Create the container
            IoC.Container = new WindsorContainer();

            // Add the Array Resolver, so we can take dependencies on T[]
            // while only registering T.
            IoC.Container.Kernel.Resolver.AddSubResolver(new ArrayResolver(IoC.Container.Kernel));

            // Register the kernel and container, in case an installer needs it.
            IoC.Container.Register(
                Component.For <IKernel>().Instance(IoC.Container.Kernel),
                Component.For <IWindsorContainer>().Instance(IoC.Container)
                );

            // Our configuration magic, register all interfaces ending in Config from
            // this assembly, and create implementations using DictionaryAdapter
            // from the AppSettings in our app.config.
            var daf = new DictionaryAdapterFactory();
            IoC.Container.Register(
                Types
                .FromThisAssembly()
                .Where(type => type.IsInterface && type.Name.EndsWith("Config"))
                .Configure(
                    reg => reg.UsingFactoryMethod(
                        (k, m, c) => daf.GetAdapter(m.Implementation, ConfigurationManager.AppSettings)
                        )
                    ));

            // Our session magic, register all interfaces ending in Session from
            // this assembly, and create implementations using DictionaryAdapter
            // from the current HttpSession
            IoC.Container.Register(
                Types
                .FromThisAssembly()
                .Where(type => type.IsInterface && type.Name.EndsWith("Session"))
                .Configure(
                    reg => reg.UsingFactoryMethod(
                        (k, m, c) => daf.GetAdapter(m.Implementation, new SessionDictionary(HttpContext.Current.Session) as IDictionary)
                        )
                    ).LifestylePerWebRequest());


            // Search for an use all installers in this application.
            IoC.Container.Install(FromAssembly.This());

#pragma warning restore 618
        }
Пример #9
0
        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 Start()
            {
                IoC.Container.Install(FromAssembly.This());

                hostedService = IoC.Container.Resolve <IHostedService>();
                startEvents   = IoC.Container.ResolveAll <IStartServiceEvent>();
                stopEvents    = IoC.Container.ResolveAll <IStopServiceEvent>();

                foreach (var startServiceEvent in startEvents.OrderBy(e => e.Order))
                {
                    startServiceEvent.Execute();
                }

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

            IocContainer.Setup();

            var container = new WindsorContainer();

            container.Install(FromAssembly.This());
            GlobalConfiguration.Configuration.DependencyResolver = new ApiDependencyResolver(container.Kernel);
        }
Пример #12
0
        private static void SharedWiring(IWindsorContainer container)
        {
            container.Register(
                Component.For <IWindsorContainer>().Instance(container),
                Classes.FromThisAssembly().BasedOn <Controller>().WithServiceSelf().LifestyleTransient(),
                Component.For <IConnectionStringProvider>().Instance(new ConnectionStringConfigurationParameterProvider()).LifestyleSingleton()
                );

            container.Install(
                FromAssembly.Containing <Domain.ContainerInstallers.AccountRepositoryInstaller>(),
                FromAssembly.Containing <Domain.Events.EventStore.ContainerInstallers.AccountManagementDomainEventStoreInstaller>(),
                FromAssembly.Containing <UI.QueryModels.ContainerInstallers.AccountManagementDocumentDbReaderInstaller>(),
                FromAssembly.Containing <UI.QueryModels.DocumentDB.Updaters.ContainerInstallers.AccountManagementQuerymodelsSessionInstaller>()
                );
        }
Пример #13
0
        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)));
            }
        }
Пример #14
0
        public void TestFixtureSetup()
        {
            //Hackery in order to get the PerWebRequest lifecycle working in a test environment
            //Surely there must be a better way to do this?
            HttpContext.Current = new HttpContext(new HttpRequest("foo", "http://localhost", ""), new HttpResponse(new StringWriter()))
            {
                ApplicationInstance = new HttpApplication()
            };
            var module = new PerWebRequestLifestyleModule();

            module.Init(HttpContext.Current.ApplicationInstance);

            container = ContainerBuilder.Build("Windsor.config");
            container.Install(FromAssembly.Containing <HomeController>());
        }
Пример #15
0
        static void Main(string[] args)
        {
            di.Install(FromAssembly.This());

            var repository = di.Resolve <IPersonRepository>();

            var persons = repository.GetCatsByOwnerGender();

            WritePets(persons);

            Console.WriteLine();
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
            di.Dispose();
        }
Пример #16
0
        public static void ConfigureWindsor(HttpConfiguration configuration)
        {
            _container = new WindsorContainer();

            _container.Install(FromAssembly.This());
            _container.Install(FromAssembly.Named("Cherries.Services.Bootstrapper"));
            _container.Install(FromAssembly.Named("TFI.BusinessLogic.Bootstraper"));

            _container.Kernel.Resolver.AddSubResolver(new CollectionResolver(_container.Kernel, true));

            var dependencyResolver = new WindsorDependencyResolver(_container);

            configuration.DependencyResolver = dependencyResolver;
            GlobalHost.DependencyResolver    = new SignalrWindsorDependencyResolver(_container);
        }
Пример #17
0
        /// <summary>
        /// Configures the windsor configuration.
        /// </summary>
        private void ConfigureWindsorConfig()
        {
            _container = new WindsorContainer();
            _container.Install(FromAssembly.This());
            //GlobalConfiguration.Configuration.Services.Replace(
            //    typeof(DefaultControllerFactory),
            //    new WindsorCompositionRoot(_container.Kernel));
            var controllerFactory = new WindsorCompositionRoot(_container.Kernel);

            ControllerBuilder.Current.SetControllerFactory(controllerFactory);
            _container.Kernel.Resolver.AddSubResolver(new CollectionResolver(_container.Kernel, true));
            var dependencyResolver = new WindsorDependencyResolver(_container);

            GlobalConfiguration.Configuration.DependencyResolver = dependencyResolver;
        }
Пример #18
0
        public static void Bootstrap()
        {
            if (!bootstrapped)
            {
                WindsorContainer = new WindsorContainer();

                var assemblyFilter = new AssemblyFilter(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"));

                Descriptor = Classes.FromAssemblyInDirectory(assemblyFilter);

                WindsorContainer.Install(FromAssembly.InDirectory(assemblyFilter));

                bootstrapped = true;
            }
        }
Пример #19
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            // Setup DocumentDB schema.
            DocumentDbConfig.Initialize();
            // Setup IoC container for ApiControllers.
            container = new WindsorContainer().Install(FromAssembly.This());
            WindsorControllerActivator activator = new WindsorControllerActivator(container.Kernel);

            GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator), activator);
        }
Пример #20
0
        private void ConfigureContainer()
        {
            _Container = new WindsorContainer();

            _Container.Install(FromAssembly.This());
            _Container.InstallFrom()
            .System()
            .Command()
            .Data();

            ILoggerFactory factory = _Container.Resolve <ILoggerFactory>();

            _Logger     = factory.Create(Loggers.Commanding.Worker);
            _jobservice = _Container.Resolve <IJobService>();
        }
Пример #21
0
        protected override void Configure()
        {
            container
            .Kernel
            .Resolver
            .AddSubResolver(new CollectionResolver(container.Kernel));

            container
            .AddFacility <TypedFactoryFacility>()
            .AddFacility <EventAggregatorFacility>()
            .Install(FromAssembly.Named("ClipboardMachinery.Core"))
            .Install(FromAssembly.This());

            logger = container.Resolve <ILogger>();
        }
Пример #22
0
        private static void InitializeServiceLocator()
        {
            IWindsorContainer container = new WindsorContainer(new XmlInterpreter());

            ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));

            container.Install(
                FromAssembly.Containing <ServiceInstaller>(),
                FromAssembly.This(),
                FromAssembly.Containing <ControllerInstaller>(),
                FromAssembly.Containing <TasksInstaller>(),
                FromAssembly.Containing <GenericRepositoryInstaller>());

            return;
        }
Пример #23
0
        private static void InitializeCastle()
        {
            var currentAssembly         = System.Reflection.Assembly.GetExecutingAssembly();
            var codeBaseAbsolutePathUri = new Uri(currentAssembly.GetName().CodeBase).AbsolutePath;
            var path = Uri.UnescapeDataString(System.IO.Path.GetDirectoryName(codeBaseAbsolutePathUri));

            var filter = new AssemblyFilter(path);


            var castle = new WindsorContainer();

            castle.AddFacility <TypedFactoryFacility>();
            castle.Install(FromAssembly.InDirectory(filter));
            container = castle;
        }
Пример #24
0
 static ViewModelLocator()
 {
     try
     {
         container = new WindsorContainer();
         //container.Install(FromAssembly.InThisEntry());
         container.Install(FromAssembly.Containing <ViewModelLocator>());
         //container.Install(FromAssembly.InThisApplication());
         //MessageBox.Show("Moo");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(
                Classes.FromThisAssembly()
                .IncludeNonPublicTypes()
                .Pick()
                .WithServiceBase().WithServiceAllInterfaces()
                .LifestyleTransient()
                .Configure(c => c.LifestyleTransient()
                           )
                );


            container.Install(FromAssembly.Containing(typeof(ApiInstaller)));
        }
Пример #26
0
        public static void Main()
        {
            Console.Title = "Telegram Dating Bot <3";

            Container.Current.Install(FromAssembly.This());

            var me = Container.Current.Resolve <BotWorker>().Instance.GetMeAsync().Result;

            Console.WriteLine($"Listening: {me.FirstName}\n");

            while (true)
            {
                ;
            }
        }
Пример #27
0
        /// <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);
        }
Пример #28
0
        public void Configuration(IAppBuilder appBuilder)
        {
            HttpConfiguration httpConfiguration = new HttpConfiguration();

            Register(httpConfiguration);
            appBuilder.UseWebApi(httpConfiguration);

            var container = new WindsorContainer();

            container.Install(FromAssembly.This());
            container.Register(
                Component.For <IRepository <Person> >().ImplementedBy <CommaDelimitedDataRepository <Person> >()
                );
            GlobalConfiguration.Configuration.DependencyResolver = new Dependencies.DependencyResolver(container.Kernel);
        }
Пример #29
0
        protected override void ConfigureApplicationContainer(IWindsorContainer existingContainer)
        {
            base.ConfigureApplicationContainer(existingContainer);

            // Add the Array Resolver, so we can take dependencies on T[]
            // while only registering T.
            existingContainer.Kernel.Resolver.AddSubResolver(new ArrayResolver(existingContainer.Kernel));
            // todo use in Selkie project

            existingContainer.Install(FromAssembly.Containing(typeof(Installer)));
            existingContainer.Install(FromAssembly.Containing(typeof(MicroServices.Days.Nancy.Installer)));
            existingContainer.Install(FromAssembly.Containing(typeof(MicroServices.Doctors.Nancy.Installer)));
            existingContainer.Install(FromAssembly.Containing(typeof(MicroServices.DoctorsSlots.Nancy.Installer)));
            existingContainer.Install(FromAssembly.Containing(typeof(MicroServices.Slots.Nancy.Installer)));
        }
Пример #30
0
        protected override void OnStartup(StartupEventArgs e)
        {
            container = new WindsorContainer();
            container.Install(FromAssembly.This());
            appInit = container.Resolve <ApplicationInitialization>();

            // prepare view-models before showing main window
            appInit.InitializeBeforeShowingTheWindow();
            appInit.ShowWindow();

            // to have the ability to show messages, we must have main Window shown
            // hence attach central error handler after the window is displayed
            DispatcherUnhandledException += App_DispatcherUnhandledException;
            appInit.InitializeAfterShowingTheWindow();
        }