示例#1
0
    public void Init(IWindsorContainer container)
    {
        container.Register(Component.For <IMessageSenderComponent>().ImplementedBy <MessageSenderComponent>().Interceptors(typeof(ComponentsInterceptor)));
        //container.Register(Component.For<IMessageSenderComponent>().ImplementedBy<MessageSenderComponent>());
        //container.Register(
        //    Component.For<IMessageSenderComponent>().ImplementedBy<MessageSenderComponent>().Interceptors(typeof(ProxyBaseInterceptor)));

        //2.yöntem
        //container.Register(
        //       Component.For<IMessageSenderComponent>().ImplementedBy<MessageSenderComponent>().Interceptors(InterceptorReference.ForType<ProxyBaseInterceptor>()).Anywhere);
    }
        protected void RegisterInterfaces(Assembly assembly, IWindsorContainer container, ICollection <Type> targetInterfaces)
        {
            var classes = assembly.ExportedTypes
                          .Select(t => t.GetTypeInfo())
                          .Where(IsConcreteClass);

            var interfaces = classes.SelectMany(c => c
                                                .ImplementedInterfaces.Where(i => IsTargetInterface(targetInterfaces, i.GetTypeInfo()))
                                                .Select(i => new KeyValuePair <Type, Type>(i.GetTypeInfo(), c.AsType())))
                             .ToList();

            foreach (var classInterface in interfaces)
            {
                container.Register(Component.For(classInterface.Key).ImplementedBy(classInterface.Value).LifestyleSingleton());
            }
        }
示例#3
0
        // registers factory from configuration
        protected void RegisterFactory(string id, Type type, string selector)
        {
            var factory = Component.For(type).Named(id);

            if (selector == null)
            {
                factory.AsFactory();
            }
            else
            {
                var selectorKey = ReferenceExpressionUtil.ExtractComponentKey(selector);
                factory.AsFactory(x => x.SelectedWith(selectorKey));
            }

            Kernel.Register(factory);
        }
示例#4
0
        public void Install()
        {
            this.Container = new WindsorContainer();
            this.Container.Register(Component.For <IWindsorContainer, WindsorContainer>().Instance(this.Container));
            this.Container.AddFacility <TypedFactoryFacility>();
            this.Container.Install(FromAssembly.Containing <Startup>());

            Mapper.Initialize(mapper =>
            {
                foreach (var mapping in this.Container.ResolveAll <IMapping>())
                {
                    mapping.Configure(mapper);
                }
            });
            Mapper.AssertConfigurationIsValid();
        }
示例#5
0
 public void Install(IWindsorContainer container, IConfigurationStore store)
 {
     container.Register(
         Component.For <Func <DbContext> >()
         .Instance(() => new AuctionPortalDbContext())
         .LifestyleTransient(),
         Component.For <IUnitOfWorkProvider>()
         .ImplementedBy <EntityFrameworkUnitOfWorkProvider>()
         .LifestyleSingleton(),
         Component.For(typeof(IRepository <>))
         .ImplementedBy(typeof(EntityFrameworkRepository <>))
         .LifestyleTransient(),
         Component.For(typeof(IQuery <>))
         .ImplementedBy(typeof(EntityFrameworkQuery <>))
         .LifestyleTransient()
         );
 }
        private void RegisterWorkerComponents(WorkerApplication application, Prototype prototype)
        {
            var buses = Utils.FindAllInstances <AzureServiceBusQueue>(prototype);

            foreach (var bus in buses)
            {
                Container.Register(
                    Component.For <HandlerGenerator>().ImplementedBy <HandlerGenerator>().LifestyleSingleton().DependsOn(Dependency.OnValue("projectName", NamingConstants.WorkerName)).DependsOn(Dependency.OnValue(
                                                                                                                                                                                                      "modelParameters", application.Actions)).DependsOn(Dependency.OnValue("azureServiceBusQueue", bus)).Named(bus.Name + typeof(HandlerGenerator))
                    );
            }

            Container.Register(
                Component.For <WorkerContainerInstallerGenerator>().ImplementedBy <WorkerContainerInstallerGenerator>().LifestyleSingleton().DependsOn(Dependency.OnValue("projectName", NamingConstants.WorkerName)),
                Component.For <WorkerMainGenerator>().ImplementedBy <WorkerMainGenerator>().LifestyleSingleton().DependsOn(Dependency.OnValue("projectName", NamingConstants.WorkerName))
                );
        }
示例#7
0
        private void WireUpDependencyResolvers()
        {
            Castle.Core.Resource.ConfigResource source = new Castle.Core.Resource.ConfigResource();
            XmlInterpreter interpreter = new XmlInterpreter(source);

            IocContext.WindsorContainer = new WindsorContainer(interpreter);
            IocContext.WindsorContainer.Register(Classes.FromThisAssembly().BasedOn <ApiController>().LifestylePerWebRequest());
            IocContext.WindsorContainer.Register(Classes.FromThisAssembly().BasedOn <Controller>().LifestylePerWebRequest());
            //IocContext.WindsorContainer.Register(
            //    Component.For<IUnitOfWork>().ImplementedBy<DemoUnitOfWorkContext>().LifestylePerThread());
            IocContext.WindsorContainer.Register(
                Component.For <IUow>().ImplementedBy <Uow>().LifestylePerThread());
            IocContext.WindsorContainer.Register(
                Component.For <IUDbContext>().ImplementedBy <UDbcontext>().LifestylePerThread());
            GlobalConfiguration.Configuration.DependencyResolver = new WindsorDependencyResolver(IocContext.WindsorContainer);
            //ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(IocContext.WindsorContainer));
        }
示例#8
0
 private static void RegisterDockablePresenters(IWindsorContainer container)
 {
     container.Register(Component.For <IDockablePresenter>()
                        .ImplementedBy <SourceControlDockablePresenter>()
                        .LifestyleSingleton());
     container.Register(Component.For <IDockablePresenter>()
                        .ImplementedBy <TestExplorerDockablePresenter>()
                        .LifestyleSingleton());
     container.Register(Component.For <IDockablePresenter>()
                        .ImplementedBy <InspectionResultsDockablePresenter>()
                        .LifestyleSingleton());
     container.Register(Component.For <IDockablePresenter>()
                        .ImplementedBy <CodeExplorerDockablePresenter>()
                        .LifestyleSingleton());
     container.Register(Component.For <IDockablePresenter>()
                        .ImplementedBy <ToDoExplorerDockablePresenter>()
                        .LifestyleSingleton());
 }
示例#9
0
        static void Main(string[] args)
        {
            var container = new WindsorContainer();

            container.Kernel.Resolver.AddSubResolver(new ArrayResolver(container.Kernel));

            container.Install(new RouterInstaller(new IRouterConfigurationSource[] { new RouterConfigurationSourceSample() }));
            container.Install(new AzureServiceBusRouterInstaller());
            container.Register(Component.For(typeof(IMessageHandler)).ImplementedBy(typeof(MessageHandler)).Named(typeof(MessageHandler).FullName).LifestyleSingleton());


            container.Install(new ServiceLocatorInstaller());
            var host = container.Resolve <IHost>();

            host.Configuration.UsingAzureServiceBus();
            host.Run();
            Console.ReadLine();
        }
        // note: settings namespace classes are injected in singleton scope
        private void RegisterConfiguration(IWindsorContainer container, Assembly[] assembliesToRegister)
        {
            var experimentalTypes = new List <Type>();

            foreach (var assembly in assembliesToRegister)
            {
                container.Register(Classes.FromAssembly(assembly)
                                   .IncludeNonPublicTypes()
                                   .Where(type => type.Namespace == typeof(Configuration).Namespace &&
                                          type.NotDisabledOrExperimental(_initialSettings) &&
                                          type != typeof(ExperimentalTypesProvider))
                                   .WithService.AllInterfaces()
                                   .LifestyleSingleton());

                experimentalTypes.AddRange(assembly.GetTypes()
                                           .Where(t => Attribute.IsDefined(t, typeof(ExperimentalAttribute))));
            }

            var provider = new ExperimentalTypesProvider(experimentalTypes);

            container.Register(Component.For(typeof(IExperimentalTypesProvider))
                               .DependsOn(Dependency.OnComponent <ViewModelBase, GeneralSettingsViewModel>())
                               .LifestyleSingleton()
                               .Instance(provider));

            container.Register(Component.For <IComProjectSerializationProvider>()
                               .ImplementedBy <XmlComProjectSerializer>()
                               .LifestyleTransient());
            container.Register(Component.For(typeof(IPersistanceService <>), typeof(IFilePersistanceService <>))
                               .ImplementedBy(typeof(XmlPersistanceService <>))
                               .LifestyleSingleton());

            container.Register(Component.For(typeof(IPersistanceService <ReferenceSettings>), typeof(IFilePersistanceService <>))
                               .ImplementedBy(typeof(XmlContractPersistanceService <>))
                               .LifestyleSingleton());

            container.Register(Component.For <IConfigProvider <IndenterSettings> >()
                               .ImplementedBy <IndenterConfigProvider>()
                               .LifestyleSingleton());

            container.Register(Component.For <IConfigProvider <UnitTesting.Settings.UnitTestSettings> >()
                               .ImplementedBy <UnitTestConfigProvider>()
                               .LifestyleSingleton());
        }
示例#11
0
 private void RegisterSpecialFactories(IWindsorContainer container)
 {
     container.Register(Component.For <IFolderBrowserFactory>()
                        .ImplementedBy <DialogFactory>()
                        .LifestyleSingleton());
     container.Register(Component.For <IModuleRewriterFactory>()
                        .ImplementedBy <ModuleRewriterFactory>()
                        .DependsOn(Dependency.OnComponent("codePaneSourceCodeHandler", typeof(CodePaneSourceCodeHandler)),
                                   Dependency.OnComponent("attributesSourceCodeHandler", typeof(SourceFileHandlerSourceCodeHandlerAdapter)))
                        .LifestyleSingleton());
     container.Register(Component.For <IRubberduckParserErrorListenerFactory>()
                        .ImplementedBy <ExceptionErrorListenerFactory>()
                        .LifestyleSingleton());
     container.Register(Component.For <IParsePassErrorListenerFactory>()
                        .ImplementedBy <MainParseErrorListenerFactory>()
                        .LifestyleSingleton());
     container.Register(Component.For <PreprocessingParseErrorListenerFactory>()
                        .ImplementedBy <PreprocessingParseErrorListenerFactory>()
                        .LifestyleSingleton());
 }
        public override List <IRegistration> GetRegistrations(string projectName)
        {
            var output = new List <IRegistration>
            {
                Component.For <DataFactoryInterfaceGenerator>()
                .ImplementedBy <DataFactoryInterfaceGenerator>()
                .LifestyleSingleton()
                .DependsOn(Dependency.OnValue("projectName", projectName)),
                Component.For <StorageInterfaceGenerator>()
                .ImplementedBy <StorageInterfaceGenerator>()
                .LifestyleSingleton()
                .DependsOn(Dependency.OnValue("projectName", projectName)),
                Component.For <DataGeneratorGenerator>()
                .ImplementedBy <DataGeneratorGenerator>()
                .LifestyleSingleton()
                .DependsOn(Dependency.OnValue("projectName", projectName))
            };

            return(output);
        }
示例#13
0
        private void InitFacility()
        {
            Kernel.Register(Component.For <TypedFactoryInterceptor>()
                            .NamedAutomatically(InterceptorKey),
                            Component.For <ILazyComponentLoader>()
                            .ImplementedBy <DelegateFactory>()
                            .NamedAutomatically(DelegateFactoryKey),
                            Component.For <IProxyFactoryExtension>()
                            .ImplementedBy <DelegateProxyFactory>()
                            .LifeStyle.Transient
                            .NamedAutomatically(DelegateProxyFactoryKey),
                            Component.For <ITypedFactoryComponentSelector>()
                            .ImplementedBy <DefaultTypedFactoryComponentSelector>()
                            .NamedAutomatically(DefaultInterfaceSelectorKey),
                            Component.For <ITypedFactoryComponentSelector>()
                            .ImplementedBy <DefaultDelegateComponentSelector>()
                            .NamedAutomatically(DefaultDelegateSelectorKey));

            Kernel.ComponentModelFactory.AddContributor(new TypedFactoryCachingInspector());
        }
示例#14
0
        private static void RegisterSourceControlControls(IWindsorContainer container)
        {
            container.Register(Component.For <SourceControlViewViewModel>()
                               .LifestyleSingleton());

            container.Register(Component.For <IControlViewModel>()
                               .ImplementedBy <ChangesPanelViewModel>()
                               .Named(nameof(ChangesPanelViewModel))
                               .LifestyleTransient());
            container.Register(Component.For <IControlView>()
                               .ImplementedBy <ChangesView>()
                               .DependsOn(Dependency.OnComponent <IControlViewModel, ChangesPanelViewModel>())
                               .LifestyleTransient());

            container.Register(Component.For <IControlViewModel>()
                               .ImplementedBy <BranchesPanelViewModel>()
                               .Named(nameof(BranchesPanelViewModel))
                               .LifestyleTransient());
            container.Register(Component.For <IControlView>()
                               .ImplementedBy <BranchesView>()
                               .DependsOn(Dependency.OnComponent <IControlViewModel, BranchesPanelViewModel>())
                               .LifestyleTransient());

            container.Register(Component.For <IControlViewModel>()
                               .ImplementedBy <UnsyncedCommitsPanelViewModel>()
                               .Named(nameof(UnsyncedCommitsPanelViewModel))
                               .LifestyleTransient());
            container.Register(Component.For <IControlView>()
                               .ImplementedBy <UnsyncedCommitsView>()
                               .DependsOn(Dependency.OnComponent <IControlViewModel, UnsyncedCommitsPanelViewModel>())
                               .LifestyleTransient());

            container.Register(Component.For <IControlViewModel>()
                               .ImplementedBy <SettingsPanelViewModel>()
                               .Named(nameof(SettingsPanelViewModel))
                               .LifestyleTransient());
            container.Register(Component.For <IControlView>()
                               .ImplementedBy <SettingsView>()
                               .DependsOn(Dependency.OnComponent <IControlViewModel, SettingsPanelViewModel>())
                               .LifestyleTransient());
        }
示例#15
0
文件: Program.cs 项目: Arzybek/fp
        static WindsorContainer SetUpContainer(WindsorContainer container, string output, string input, Size size,
                                               String color, String font, bool compression, string format, IEnumerable <string> excluded)
        {
            container.Register(Component.For <TagsCloudContainer>()
                               .DependsOn(
                                   Dependency.OnValue("output", output + $".{format}"),
                                   Dependency.OnValue("input", input)
                                   ));
            container.Register(Component.For <ITextReader>()
                               .ImplementedBy <DefaultTextReader>());
            container.Register(Component.For <IWordsFilter>()
                               .ImplementedBy <DefaultWordsFilter>()
                               .DependsOn(Dependency.OnValue("excluded", excluded))
                               );
            container.Register(Component.For <IWordsCounter>()
                               .ImplementedBy <DefaultWordsCounter>());
            container.Register(Component.For <IWordsToSizesConverter>()
                               .ImplementedBy <DefaultWordsToSizesConverter>()
                               .DependsOn(Dependency.OnValue("size", size))
                               );
            container.Register(Component.For <ICloudLayouter>()
                               .ImplementedBy <CircularCloudLayouter>()
                               .DependsOn(Dependency.OnValue("center", new Point(size.Width / 2, size.Height / 2)),
                                          Dependency.OnValue("compression", compression)));
            container.Register(Component.For <IPointsGenerator>()
                               .ImplementedBy <SpiralPointsGenerator>());
            container.Register(Component.For <IVisualiser>()
                               .ImplementedBy <DefaultVisualiser>()
                               .DependsOn(
                                   Dependency.OnValue("size", size),
                                   Dependency.OnValue("color", color),
                                   Dependency.OnValue("font", font)
                                   )
                               );
            container.Register(Component.For <IFileSaver>()
                               .ImplementedBy <ImageSaver>()
                               .DependsOn(Dependency.OnValue("format", format))
                               );

            return(container);
        }
示例#16
0
        // note: settings namespace classes are injected in singleton scope
        private void RegisterConfiguration(IWindsorContainer container, Assembly[] assembliesToRegister)
        {
            var experimentalTypes = new List <Type>();

            foreach (var assembly in assembliesToRegister)
            {
                container.Register(Classes.FromAssembly(assembly)
                                   .IncludeNonPublicTypes()
                                   .Where(type => type.Namespace == typeof(Configuration).Namespace && type.NotDisabledOrExperimental(_initialSettings))
                                   .WithService.AllInterfaces()
                                   .LifestyleSingleton());

                experimentalTypes.AddRange(assembly.GetTypes()
                                           .Where(t => Attribute.IsDefined(t, typeof(ExperimentalAttribute))));
            }

            // FIXME correctly register experimentalFeatureTypes.
            // This is probably blocked until GeneralSettingsViewModel is no more newed up in SettingsForm's code-behind
            //container.Register(Component.For(typeof(IEnumerable<Type>))
            //    .DependsOn(Dependency.OnComponent<ViewModelBase, GeneralSettingsViewModel>())
            //    .LifestyleSingleton()
            //    .Instance(experimentalTypes));

            container.Register(Component.For <IComProjectSerializationProvider>()
                               .ImplementedBy <XmlComProjectSerializer>()
                               .LifestyleTransient());
            container.Register(Component.For(typeof(IPersistanceService <>), typeof(IFilePersistanceService <>))
                               .ImplementedBy(typeof(XmlPersistanceService <>))
                               .LifestyleSingleton());

            container.Register(Component.For(typeof(IPersistanceService <ReferenceSettings>), typeof(IFilePersistanceService <>))
                               .ImplementedBy(typeof(XmlContractPersistanceService <>))
                               .LifestyleSingleton());

            container.Register(Component.For <IConfigProvider <IndenterSettings> >()
                               .ImplementedBy <IndenterConfigProvider>()
                               .LifestyleSingleton());
        }
示例#17
0
        private void RegisterCommandsWithPresenters(IWindsorContainer container)
        {
            container.Register(Component.For <CommandBase>()
                               .ImplementedBy <RunAllTestsCommand>()
                               .DependsOn(Dependency.OnComponent <IDockablePresenter, TestExplorerDockablePresenter>())
                               .LifestyleTransient()
                               .Named(typeof(RunAllTestsCommand).Name));
            container.Register(Component.For <CommandBase>()
                               .ImplementedBy <TestExplorerCommand>()
                               .DependsOn(Dependency.OnComponent <IDockablePresenter, TestExplorerDockablePresenter>())
                               .LifestyleTransient()
                               .Named(typeof(TestExplorerCommand).Name));

            container.Register(Component.For <CommandBase>()
                               .ImplementedBy <InspectionResultsCommand>()
                               .DependsOn(Dependency.OnComponent <IDockablePresenter, InspectionResultsDockablePresenter>())
                               .LifestyleTransient()
                               .Named(typeof(InspectionResultsCommand).Name));

            container.Register(Component.For <CommandBase>()
                               .ImplementedBy <CodeExplorerCommand>()
                               .DependsOn(Dependency.OnComponent <IDockablePresenter, CodeExplorerDockablePresenter>())
                               .LifestyleTransient()
                               .Named(typeof(CodeExplorerCommand).Name));

            container.Register(Component.For <CommandBase>()
                               .ImplementedBy <CodeMetricsCommand>()
                               .DependsOn(Dependency.OnComponent <IDockablePresenter, CodeMetricsDockablePresenter>())
                               .LifestyleSingleton()
                               .Named(typeof(CodeMetricsCommand).Name));

            container.Register(Component.For <CommandBase>()
                               .ImplementedBy <ToDoExplorerCommand>()
                               .DependsOn(Dependency.OnComponent <IDockablePresenter, ToDoExplorerDockablePresenter>())
                               .LifestyleTransient()
                               .Named(typeof(ToDoExplorerCommand).Name));
        }
示例#18
0
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            new EntityFrameworkInstaller().Install(container, store);

            container.Register(
                Classes.FromThisAssembly()
                .BasedOn(typeof(QueryObjectBase <, , ,>))
                .WithServiceBase()
                .LifestyleTransient(),

                Classes.FromThisAssembly()
                .BasedOn <ServiceBase>()
                .WithServiceDefaultInterfaces()
                .LifestyleTransient(),

                Classes.FromThisAssembly()
                .BasedOn <FacadeBase>()
                .LifestyleTransient(),

                Component.For <IMapper>()
                .Instance(new Mapper(new MapperConfiguration(MappingConfig.ConfigureMapping)))
                .LifestyleSingleton()
                );
        }
        public Configuration Configure(IWindsorContainer container)
        {
            //Resolve all extensions to include in core mapping
            var extensionConfigurationProviders = container.ResolveAll <IExtensionNHibernateConfigurationProvider>()
                                                  .ToList();

            _entityExtensionHbmBagsByEntityName = extensionConfigurationProviders
                                                  .SelectMany(x => x.EntityExtensionHbmBagByEntityName)
                                                  .GroupBy(x => x.Key)
                                                  .ToDictionary(
                x => x.Key,
                x => x.Select(y => y.Value)
                .ToArray());

            _aggregateExtensionHbmBagsByEntityName = extensionConfigurationProviders
                                                     .SelectMany(x => x.AggregateExtensionHbmBagsByEntityName)
                                                     .GroupBy(x => x.Key)
                                                     .ToDictionary(
                x => x.Key,
                x => x.SelectMany(y => y.Value)
                .ToArray());

            _extensionDescriptorByEntityName = extensionConfigurationProviders
                                               .SelectMany(x => x.NonDiscriminatorBasedHbmJoinedSubclassesByEntityName)
                                               .GroupBy(x => x.Key)
                                               .ToDictionary(
                x => x.Key,
                x => x.SelectMany(y => y.Value)
                .ToArray());

            _extensionDerivedEntityByEntityName = extensionConfigurationProviders
                                                  .SelectMany(x => x.DiscriminatorBasedHbmSubclassesByEntityName)
                                                  .GroupBy(x => x.Key)
                                                  .ToDictionary(k => k.Key, v => v.SelectMany(y => y.Value).ToArray());

            _beforeBindMappingActivities = container.ResolveAll <INHibernateBeforeBindMappingActivity>();

            // Start the NHibernate configuration
            var configuration = new Configuration();

            // Add the configuration to the container
            container.Register(
                Component.For <Configuration>()
                .Instance(configuration));

            configuration.BeforeBindMapping += Configuration_BeforeBindMapping;

            // Get all the authorization strategy configurators
            var authorizationStrategyConfigurators = container.ResolveAll <INHibernateFilterConfigurator>();

            // Get all the filter definitions from all the configurators
            var allFilterDetails =
                (from c in authorizationStrategyConfigurators
                 from f in c.GetFilters()
                 select f)
                .Distinct()
                .ToList();

            // Group the filters by name first (there can only be 1 "default" filter, but flexibility
            // to apply same filter name with same parameters to different entities should be supported
            // (and is in fact supported below when filters are applied to individual entity mappings)
            var allFilterDetailsGroupedByName =
                from f in allFilterDetails
                group f by f.FilterDefinition.FilterName
                into g
                select g;

            // Add all the filter definitions to the NHibernate configuration
            foreach (var filterDetails in allFilterDetailsGroupedByName)
            {
                configuration.AddFilterDefinition(
                    filterDetails.First()
                    .FilterDefinition);
            }

            // Configure the mappings
            var ormMappingFileData = container.Resolve <IOrmMappingFileDataProvider>().OrmMappingFileData();

            configuration.AddResources(ormMappingFileData.MappingFileFullNames, ormMappingFileData.Assembly);

            //Resolve all extension assemblies and add to NHibernate configuration
            extensionConfigurationProviders
            .ForEach(
                e => configuration.AddResources(e.OrmMappingFileData.MappingFileFullNames, e.OrmMappingFileData.Assembly));

            var filterCriteriaApplicatorProvider = container.Resolve <IFilterCriteriaApplicatorProvider>();

            // Invoke configuration activities
            var configurationActivities = container.ResolveAll <INHibernateConfigurationActivity>();

            foreach (var configurationActivity in configurationActivities)
            {
                configurationActivity.Execute(configuration);
            }

            // Apply the previously defined filters to the mappings
            foreach (var mapping in configuration.ClassMappings)
            {
                Type entityType = mapping.MappedClass;
                var  properties = entityType.GetProperties();

                var applicableFilters = allFilterDetails
                                        .Where(filterDetails => filterDetails.ShouldApply(entityType, properties))
                                        .ToList();

                foreach (var filter in applicableFilters)
                {
                    var filterDefinition = filter.FilterDefinition;

                    // Save the filter criteria applicators
                    filterCriteriaApplicatorProvider.AddCriteriaApplicator(
                        filterDefinition.FilterName,
                        entityType,
                        filter.CriteriaApplicator);

                    mapping.AddFilter(
                        filterDefinition.FilterName,
                        filterDefinition.DefaultFilterCondition);

                    var metaAttribute = new MetaAttribute(filterDefinition.FilterName);
                    metaAttribute.AddValue(filter.HqlConditionFormatString);

                    mapping.MetaAttributes.Add(
                        "HqlFilter_" + filterDefinition.FilterName,
                        metaAttribute);
                }
            }

            // NHibernate Dependency Injection
            Environment.ObjectsFactory = new WindsorObjectsFactory(container);

            configuration.AddCreateDateHooks();

            // Build and register the session factory with the container
            container.Register(
                Component
                .For <ISessionFactory>()
                .UsingFactoryMethod(configuration.BuildSessionFactory)
                .LifeStyle.Singleton);

            container.Register(
                Component
                .For <Func <IStatelessSession> >()
                .UsingFactoryMethod <Func <IStatelessSession> >(
                    kernel => () => kernel.Resolve <ISessionFactory>().OpenStatelessSession())
                .LifestyleSingleton());     // The function is a singleton, not the session

            container.Register(
                Component
                .For <EdFiOdsConnectionProvider>()
                .DependsOn(
                    Dependency
                    .OnComponent(
                        typeof(IDatabaseConnectionStringProvider),
                        typeof(IDatabaseConnectionStringProvider).GetServiceNameWithSuffix(
                            Databases.Ods.ToString()))));

            // Register the SQL Server version of the parameter list setter
            // This is registered with the API by the SqlServerSupportConditionalFeature
            // in the non-legacy code.
            container.Register(
                Component
                .For <IParameterListSetter>()
                .ImplementedBy <SqlServerTableValuedParameterListSetter>());

            return(configuration);
        }
示例#20
0
 protected override void Init()
 {
     Kernel.Register(Component.For <ShippingCalculator>()
                     .Named("calculator")
                     .DependsOn(Property.ForKey("ShippingCost").Eq(5m)));
 }
示例#21
0
 private void RegisterConstantVbeAndAddIn(IWindsorContainer container)
 {
     container.Register(Component.For <IVBE>().Instance(_vbe));
     container.Register(Component.For <IAddIn>().Instance(_addin));
     container.Register(Component.For <ICommandBars>().Instance(_vbe.CommandBars)); //note: This registration makes Castle Windsor inject _vbe_CommandBars in all ICommandBars Parent properties.
 }
 protected T Create <T>() where T : class
 {
     Container.Register(Component.For <T>());
     return(Container.Resolve <T>());
 }
示例#23
0
        //Guidelines and words of caution:

        //1) Please always specify the Lifestyle. The default is singleton, which can be confusing.
        //2) Before adding conventions, please read the Castle Windsor online documentation; there are a few gotchas.
        //3) The first binding wins; all further bindings are only used in multibinding, unless named.
        //4) The standard name of a binding is the full type name of the implementing class.


        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            SetUpCollectionResolver(container);
            ActivateAutoMagicFactories(container);
            DeactivatePropertyInjection(container);

            RegisterConstantVbeAndAddIn(container);
            RegisterAppWithSpecialDependencies(container);

            container.Register(Component.For <RubberduckParserState, IParseTreeProvider, IDeclarationFinderProvider>()
                               .ImplementedBy <RubberduckParserState>()
                               .LifestyleSingleton());
            container.Register(Component.For <ISelectionChangeService>()
                               .ImplementedBy <SelectionChangeService>()
                               .LifestyleSingleton());
            container.Register(Component.For <ISourceControlProvider>()
                               .ImplementedBy <GitProvider>()
                               .LifestyleSingleton());
            //container.Register(Component.For<GitProvider>()
            //    .LifestyleSingleton());
            container.Register(Component.For <IOperatingSystem>()
                               .ImplementedBy <WindowsOperatingSystem>()
                               .LifestyleSingleton());

            container.Register(Component.For <DeclarationFinder>()
                               .ImplementedBy <ConcurrentlyConstructedDeclarationFinder>()
                               .LifestyleTransient());

            RegisterSmartIndenter(container);
            RegisterParsingEngine(container);

            container.Register(Component.For <TestExplorerModel>()
                               .LifestyleSingleton());

            RegisterRefactoringDialogs(container);

            container.Register(Component.For <ISearchResultsWindowViewModel>()
                               .ImplementedBy <SearchResultsWindowViewModel>()
                               .LifestyleSingleton());
            container.Register(Component.For <SearchResultPresenterInstanceManager>()
                               .LifestyleSingleton());

            RegisterSourceControlControls(container);

            RegisterDockablePresenters(container);
            RegisterDockableUserControls(container);

            RegisterCommands(container);
            RegisterCommandMenuItems(container);
            RegisterParentMenus(container);
            RegisterCodeExplorerViewModelWithCodeExplorerCommands(container);

            RegisterRubberduckCommandBar(container);
            RegisterRubberduckMenu(container);
            RegisterCodePaneContextMenu(container);
            RegisterFormDesignerContextMenu(container);
            RegisterFormDesignerControlContextMenu(container);
            RegisterProjectExplorerContextMenu(container);

            RegisterWindowsHooks(container);

            var assembliesToRegister = AssembliesToRegister().ToArray();

            RegisterConfiguration(container, assembliesToRegister);

            RegisterParseTreeInspections(container, assembliesToRegister);
            RegisterInspections(container, assembliesToRegister);
            RegisterQuickFixes(container, assembliesToRegister);

            RegisterSpecialFactories(container);
            RegisterFactories(container, assembliesToRegister);

            ApplyDefaultInterfaceConvention(container, assembliesToRegister);
        }
示例#24
0
 private static void RegisterRefactoringDialogs(IWindsorContainer container)
 {
     container.Register(Component.For <IRefactoringDialog <RenameViewModel> >()
                        .ImplementedBy <RenameDialog>()
                        .LifestyleTransient());
 }
        protected TDependency RegisterDependency <TDependency>(TDependency dependency) where TDependency : class
        {
            m_MockContainer.Register(Component.For <TDependency>().Instance(dependency));

            return(dependency);
        }
 private void RegisterTypeLibApi(IWindsorContainer container)
 {
     container.Register(Component.For <IVBETypeLibsAPI>()
                        .ImplementedBy <VBETypeLibsAPI>()
                        .LifestyleSingleton());
 }
        //Guidelines and words of caution:

        //1) Please always specify the Lifestyle. The default is singleton, which can be confusing.
        //2) Before adding conventions, please read the Castle Windsor online documentation; there are a few gotchas.
        //3) The first binding wins; all further bindings are only used in multibinding, unless named.
        //4) The standard name of a binding is the full type name of the implementing class.


        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            SetUpCollectionResolver(container);
            ActivateAutoMagicFactories(container);
            OverridePropertyInjection(container);

            RegisterInstances(container);
            RegisterAppWithSpecialDependencies(container);
            RegisterUnitTestingComSide(container);

            container.Register(Component.For <Version>()
                               .UsingFactoryMethod(() => Assembly.GetExecutingAssembly().GetName().Version)
                               .LifestyleSingleton());
            container.Register(Component.For <IProjectsProvider, IProjectsRepository>()
                               .ImplementedBy <ProjectsRepository>()
                               .LifestyleSingleton());
            container.Register(Component.For <RubberduckParserState, IParseTreeProvider, IDeclarationFinderProvider, IParseManager>()
                               .ImplementedBy <RubberduckParserState>()
                               .LifestyleSingleton());
            container.Register(Component.For <ISelectionChangeService>()
                               .ImplementedBy <SelectionChangeService>()
                               .LifestyleSingleton());
            container.Register(Component.For <ISelectionService>()
                               .ImplementedBy <SelectionService>()
                               .LifestyleSingleton());
            container.Register(Component.For <AutoCompleteService>()
                               .LifestyleSingleton());
            container.Register(Component.For <IOperatingSystem>()
                               .ImplementedBy <WindowsOperatingSystem>()
                               .LifestyleSingleton());

            container.Register(Component.For <DeclarationFinder>()
                               .ImplementedBy <ConcurrentlyConstructedDeclarationFinder>()
                               .LifestyleTransient());

            RegisterSmartIndenter(container);
            RegisterParsingEngine(container);
            RegisterTypeLibApi(container);

            container.Register(Component.For <IRewritingManager>()
                               .ImplementedBy <RewritingManager>()
                               .LifestyleSingleton());
            container.Register(Component.For <IMemberAttributeRecovererWithSettableRewritingManager>()
                               .ImplementedBy <MemberAttributeRecoverer>()
                               .LifestyleSingleton());

            container.Register(Component.For <TestExplorerModel>()
                               .LifestyleSingleton());
            container.Register(Component.For <IVBEInteraction>()
                               .ImplementedBy <VBEInteraction>()
                               .LifestyleSingleton());

            RegisterSettingsViewModel(container);
            RegisterRefactoringDialogs(container);

            container.Register(Component.For <ISearchResultsWindowViewModel>()
                               .ImplementedBy <SearchResultsWindowViewModel>()
                               .LifestyleSingleton());
            container.Register(Component.For <SearchResultPresenterInstanceManager>()
                               .LifestyleSingleton());

            RegisterRefactoringDialogs(container);
            RegisterDockablePresenters(container);
            RegisterDockableUserControls(container);

            RegisterCommands(container);
            RegisterCommandMenuItems(container);
            RegisterParentMenus(container);

            RegisterRubberduckCommandBar(container);
            RegisterRubberduckMenu(container);
            RegisterCodePaneContextMenu(container);
            RegisterFormDesignerContextMenu(container);
            RegisterFormDesignerControlContextMenu(container);
            RegisterProjectExplorerContextMenu(container);

            RegisterWindowsHooks(container);

            container.Register(Component.For <HotkeyFactory>()
                               .LifestyleSingleton());
            container.Register(Component.For <ITestEngine>()
                               .ImplementedBy <TestEngine>()
                               .LifestyleSingleton());

            var assembliesToRegister = AssembliesToRegister().ToArray();

            RegisterConfiguration(container, assembliesToRegister);

            RegisterParseTreeInspections(container, assembliesToRegister);
            RegisterInspections(container, assembliesToRegister);
            RegisterQuickFixes(container, assembliesToRegister);
            RegisterAutoCompletes(container, assembliesToRegister);
            RegisterCodeMetrics(container, assembliesToRegister);

            RegisterSpecialFactories(container);
            RegisterFactories(container, assembliesToRegister);

            ApplyDefaultInterfaceConvention(container, assembliesToRegister);
        }
        private void RegisterParsingEngine(IWindsorContainer container)
        {
            RegisterCustomDeclarationLoadersToParser(container);

            container.Register(Component.For <ICompilationArgumentsProvider, ICompilationArgumentsCache>()
                               .ImplementedBy <CompilationArgumentsCache>()
                               .DependsOn(Dependency.OnComponent <ICompilationArgumentsProvider, CompilationArgumentsProvider>())
                               .LifestyleSingleton());
            container.Register(Component.For <ICOMReferenceSynchronizer, IProjectReferencesProvider>()
                               .ImplementedBy <COMReferenceSynchronizer>()
                               .DependsOn(Dependency.OnValue <string>(null))
                               .LifestyleSingleton());
            container.Register(Component.For <IBuiltInDeclarationLoader>()
                               .ImplementedBy <BuiltInDeclarationLoader>()
                               .LifestyleSingleton());
            container.Register(Component.For <IDeclarationResolveRunner>()
                               .ImplementedBy <DeclarationResolveRunner>()
                               .LifestyleSingleton());
            container.Register(Component.For <IModuleToModuleReferenceManager>()
                               .ImplementedBy <ModuleToModuleReferenceManager>()
                               .LifestyleSingleton());
            container.Register(Component.For <ISupertypeClearer>()
                               .ImplementedBy <SupertypeClearer>()
                               .LifestyleSingleton());
            container.Register(Component.For <IParserStateManager>()
                               .ImplementedBy <ParserStateManager>()
                               .LifestyleSingleton());
            container.Register(Component.For <IParseRunner>()
                               .ImplementedBy <ParseRunner>()
                               .LifestyleSingleton());
            container.Register(Component.For <IParsingStageService>()
                               .ImplementedBy <ParsingStageService>()
                               .LifestyleSingleton());
            container.Register(Component.For <IParsingCacheService>()
                               .ImplementedBy <ParsingCacheService>()
                               .LifestyleSingleton());
            container.Register(Component.For <IProjectManager>()
                               .ImplementedBy <RepositoryProjectManager>()
                               .LifestyleSingleton());
            container.Register(Component.For <IReferenceRemover>()
                               .ImplementedBy <ReferenceRemover>()
                               .LifestyleSingleton());
            container.Register(Component.For <IReferenceResolveRunner>()
                               .ImplementedBy <ReferenceResolveRunner>()
                               .LifestyleSingleton());
            container.Register(Component.For <IParseCoordinator>()
                               .ImplementedBy <ParseCoordinator>()
                               .LifestyleSingleton());
            container.Register(Component.For <IComLibraryProvider>()
                               .ImplementedBy <ComLibraryProvider>()
                               .LifestyleSingleton());
            container.Register(Component.For <IReferencedDeclarationsCollector>()
                               .ImplementedBy <LibraryReferencedDeclarationsCollector>()
                               .LifestyleSingleton());
            container.Register(Component.For <ITokenStreamPreprocessor>()
                               .ImplementedBy <VBAPreprocessor>()
                               .DependsOn(Dependency.OnComponent <ITokenStreamParser, VBAPreprocessorParser>())
                               .LifestyleSingleton());
            container.Register(Component.For <VBAPredefinedCompilationConstants>()
                               .ImplementedBy <VBAPredefinedCompilationConstants>()
                               .DependsOn(Dependency.OnValue <double>(double.Parse(_vbe.Version, CultureInfo.InvariantCulture)))
                               .LifestyleSingleton());
            container.Register(Component.For <VBAPreprocessorParser>()
                               .ImplementedBy <VBAPreprocessorParser>()
                               .DependsOn(Dependency.OnComponent <IParsePassErrorListenerFactory, PreprocessingParseErrorListenerFactory>())
                               .LifestyleSingleton());
            container.Register(Component.For <ICommonTokenStreamProvider>()
                               .ImplementedBy <SimpleVBAModuleTokenStreamProvider>()
                               .LifestyleSingleton());
            container.Register(Component.For <IStringParser>()
                               .ImplementedBy <TokenStreamParserStringParserAdapterWithPreprocessing>()
                               .LifestyleSingleton());
            container.Register(Component.For <ITokenStreamParser>()
                               .ImplementedBy <VBATokenStreamParser>()
                               .LifestyleSingleton());
            container.Register(Component.For <IModuleParser>()
                               .ImplementedBy <ModuleParser>()
                               .DependsOn(Dependency.OnComponent("codePaneSourceCodeProvider", typeof(CodePaneSourceCodeHandler)),
                                          Dependency.OnComponent("attributesSourceCodeProvider", typeof(SourceFileHandlerSourceCodeHandlerAdapter)))
                               .LifestyleSingleton());
            container.Register(Component.For <ITypeLibWrapperProvider>()
                               .ImplementedBy <TypeLibWrapperProvider>()
                               .LifestyleSingleton());
        }
 protected void RegisterDependency <TService, TDependency>() where TDependency : TService where TService : class
 {
     m_MockContainer.Register(Component.For <TService>().ImplementedBy <TDependency>());
 }
 private void RegisterUnitTestingComSide(IWindsorContainer container)
 {
     container.Register(Component.For <IFakesFactory>()
                        .ImplementedBy <FakesProviderFactory>()
                        .LifestyleSingleton());
 }