示例#1
0
        /// <summary>
        /// Configure the injection scope
        /// </summary>
        /// <param name="registrationBlock"></param>
        public void Configure(Action <IExportRegistrationBlock> registrationBlock)
        {
            lock (GetLockObject(ActivationStrategyAddLockName))
            {
                var provider = ScopeConfiguration.Implementation.Locate <IExportRegistrationBlockValueProvider>();

                registrationBlock(provider);

                foreach (var inspector in provider.GetInspectors())
                {
                    StrategyCollectionContainer.AddInspector(inspector);
                    WrapperCollectionContainer.AddInspector(inspector);
                    DecoratorCollectionContainer.AddInspector(inspector);
                }

                foreach (var missingExportStrategyProvider in provider.GetMissingExportStrategyProviders())
                {
                    InternalFieldStorage.MissingExportStrategyProviders = InternalFieldStorage.MissingExportStrategyProviders.Add(missingExportStrategyProvider);
                }

                foreach (var injectionValueProvider in provider.GetValueProviders())
                {
                    InternalFieldStorage.ValueProviders = InternalFieldStorage.ValueProviders.Add(injectionValueProvider);
                }

                foreach (var compiledWrapperStrategy in provider.GetWrapperStrategies())
                {
                    WrapperCollectionContainer.AddStrategy(compiledWrapperStrategy);
                }

                foreach (var decorator in provider.GetDecoratorStrategies())
                {
                    DecoratorCollectionContainer.AddStrategy(decorator);
                }

                foreach (var strategy in provider.GetExportStrategies())
                {
                    StrategyCollectionContainer.AddStrategy(strategy);

                    foreach (var secondaryStrategy in strategy.SecondaryStrategies())
                    {
                        StrategyCollectionContainer.AddStrategy(secondaryStrategy);
                    }
                }

                foreach (var selector in provider.GetMemberInjectionSelectors())
                {
                    InternalFieldStorage.MemberInjectionSelectors = InternalFieldStorage.MemberInjectionSelectors.Add(selector);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Configuration object constructor
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="parent"></param>
        /// <param name="name"></param>
        public InjectionScope(IInjectionScopeConfiguration configuration, IInjectionScope parent, string name) :
            base(parent, name, new ImmutableHashTree <Type, ActivationStrategyDelegate> [configuration.CacheArraySize])
        {
            configuration.SetInjectionScope(this);

            InternalFieldStorage.ScopeConfiguration = configuration;

            InternalFieldStorage.InjectionContextCreator = configuration.Implementation.Locate <IInjectionContextCreator>();

            InternalFieldStorage.CanLocateTypeService = configuration.Implementation.Locate <ICanLocateTypeService>();

            InternalFieldStorage.ActivationStrategyCompiler = configuration.Implementation.Locate <IActivationStrategyCompiler>();

            InternalFieldStorage.StrategyCollectionContainer =
                AddDisposable(configuration.Implementation.Locate <IActivationStrategyCollectionContainer <ICompiledExportStrategy> >());

            InternalFieldStorage.DecoratorCollectionContainer =
                AddDisposable(configuration.Implementation.Locate <IActivationStrategyCollectionContainer <ICompiledDecoratorStrategy> >());

            for (var i = 0; i <= ArrayLengthMinusOne; i++)
            {
                ActivationDelegates[i] = ImmutableHashTree <Type, ActivationStrategyDelegate> .Empty;
            }

            if (configuration.AutoRegisterUnknown && Parent == null)
            {
                InternalFieldStorage.MissingExportStrategyProviders =
                    InternalFieldStorage.MissingExportStrategyProviders.Add(
                        configuration.Implementation.Locate <IMissingExportStrategyProvider>());
            }

            if (configuration.SupportFuncType)
            {
                StrategyCollectionContainer.AddStrategy(new FuncTypeStrategy(this));
            }

            DisposalScopeProvider = configuration.DisposalScopeProvider;

            DisposalScope = DisposalScopeProvider == null ? this : null;
        }