Example #1
0
        public object[] GetParameters(IBuilderContext context, Type type, string id, ConstructorInfo constructor)
        {
            ParameterInfo[] parms = constructor.GetParameters();
            object[] parmsValueArray = new object[parms.Length];

            for (int i = 0; i < parms.Length; ++i)
            {
                if (typeof(IEnumerable).IsAssignableFrom(parms[i].ParameterType))
                {
                    Type genericList = typeof(List<>);
                    Type fullType = genericList.MakeGenericType(parms[i].ParameterType.GetGenericArguments()[0]);
                    parmsValueArray[i] = Activator.CreateInstance(fullType);

                    foreach (object o in Core.Objects.ObjectFactory.BuildAll(parms[i].ParameterType.GetGenericArguments()[0]))
                    {
                        ((IList)parmsValueArray[i]).Add(o);
                    }
                }
                else
                {
                    parmsValueArray[i] = Core.Objects.ObjectFactory.BuildUp(parms[i].ParameterType);
                }
            }
            return parmsValueArray;
        }
 public override void PreBuildUp(IBuilderContext context)
 {
     base.PreBuildUp(context);
     //novos objetos
     if (context.Existing == null)
         _logger.Log(String.Format("CREATING {0}", context.BuildKey.ToString()), Category.Debug, Priority.None);
 }
        public override void PreBuildUp(IBuilderContext context)
        {
            var key = context.OriginalBuildKey;

            if (!key.Type.IsInterface)
            {
                // We only record for interfaces
                return;
            }

            var existing = context.Existing;

            if (existing == null)
            {
                return;
            }

            if (_settings.InterestingTypes.Count > 0)
            {
                if (!_settings.InterestingTypes.Contains(key.Type.FullName))
                {
                    return;
                }
            }

            Debug.WriteLine("Instantiated " + existing.GetType().FullName);
            Debug.WriteLine("ResolvedFrom " + key.Type.FullName);

            var replacement = _recorder.Record(context.OriginalBuildKey.Type, context.Existing);

            Debug.WriteLine("ReplacedWith " + replacement.GetType().FullName);

            context.Existing = replacement;
        }
        private object BuildUpNewObject(IBuilderContext context, Type typeToBuild, object existing, string idToBuild)
        {
            ICreationPolicy policy = context.Policies.Get<ICreationPolicy>(typeToBuild, idToBuild);

            if (policy == null)
            {
                if (idToBuild == null)
                    throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                        Properties.Resources.MissingPolicyUnnamed, typeToBuild));
                else
                    throw new ArgumentException(String.Format(CultureInfo.CurrentCulture,
                        Properties.Resources.MissingPolicyNamed, typeToBuild, idToBuild));
            }

            try
            {
                existing = FormatterServices.GetSafeUninitializedObject(typeToBuild);
            }
            catch (MemberAccessException exception)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Properties.Resources.CannotCreateInstanceOfType, typeToBuild), exception);
            }

            RegisterObject(context, typeToBuild, existing, idToBuild);
            InitializeObject(context, existing, idToBuild, policy);
            return existing;
        }
Example #5
0
        /// <summary>Builds the dependency demands required by this implementation. </summary>
        /// <param name="containerBuilder">The <see cref="IContainerBuilder"/> .</param>
        /// <param name="context">The context for this building session containing configuration etc.</param>
        public void Build(IContainerBuilder containerBuilder, IBuilderContext context)
        {
            containerBuilder
                .ForFactory(x => new IndexConfiguration(context.MapPath("~/App_Data/DiskCaches/Lucene/")))
                .KnownAsSelf()
                .ScopedAs.Singleton();

            //containerBuilder
            //    .ForFactory(x => new IndexController(x.Resolve<IndexConfiguration>(), null))
            //    .KnownAsSelf()
            //    .OnActivated((ctx, ctrlr) =>
            //    {
            //        var frameworkContext = ctx.Resolve<IFrameworkContext>();
            //        ctrlr.SetFrameworkContext(frameworkContext);
            //    })
            //    .ScopedAs.Singleton();

            containerBuilder
                .ForFactory(x => new IndexController(x.Resolve<IndexConfiguration>(), x.Resolve<IFrameworkContext>))
                .KnownAsSelf()
                //.OnActivated((ctx, ctrlr) =>
                //{
                //    var frameworkContext = ctx.Resolve<IFrameworkContext>();
                //    ctrlr.SetFrameworkContext(frameworkContext);
                //})
                .ScopedAs.Singleton();
        }
 /// <summary>
 ///   Return the sequence of methods to call while building the target object.
 /// </summary>
 /// <param name = "context">Current build context.</param>
 /// <param name = "resolverPolicyDestination">The <see cref = 'IPolicyList' /> to add any
 ///   generated resolver objects into.</param>
 /// <returns>Sequence of methods to call.</returns>
 public IEnumerable<SelectedMethod> SelectMethods(IBuilderContext context, IPolicyList resolverPolicyDestination)
 {
     foreach (Pair<MethodInfo, IEnumerable<InjectionParameterValue>> method in methods)
     {
         Type typeToBuild = context.BuildKey.Type;
         SelectedMethod selectedMethod;
         var typeReflector = new ReflectionHelper(method.First.DeclaringType);
         var methodReflector = new MethodReflectionHelper(method.First);
         if (!methodReflector.MethodHasOpenGenericParameters && !typeReflector.IsOpenGeneric)
         {
             selectedMethod = new SelectedMethod(method.First);
         }
         else
         {
             Type[] closedMethodParameterTypes =
                 methodReflector.GetClosedParameterTypes(typeToBuild.GetGenericArguments());
             selectedMethod = new SelectedMethod(
                 typeToBuild.GetMethod(method.First.Name, closedMethodParameterTypes));
         }
         SpecifiedMemberSelectorHelper.AddParameterResolvers(
             typeToBuild,
             resolverPolicyDestination,
             method.Second,
             selectedMethod);
         yield return selectedMethod;
     }
 }
        public override void PreBuildUp(IBuilderContext context)
        {
            var type = context.BuildKey.Type;
            if (!type.FullName.StartsWith("Microsoft.Practices"))
            {
                var properties = type.GetProperties();

                foreach (var property in properties)
                {
                    if (!property.CanWrite)
                        continue;

                    if (_unityContainer.IsRegistered(property.PropertyType))
                    {
                        property.SetValue(context.Existing, _unityContainer.Resolve(property.PropertyType),null);
                    }

                    if(configuredProperties.ContainsKey(type))
                    {
                        var p = configuredProperties[type].FirstOrDefault(t => t.Item1 == property.Name);

                        if(p != null)
                            property.SetValue(context.Existing, p.Item2,null);
                    }
                }
            }
        }
        public override void PreBuildUp(
            IBuilderContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            IPolicyList policySource;
            var lifetimePolicy = context
                .PersistentPolicies
                .Get<ILifetimePolicy>(context.BuildKey,
                    out policySource);

            if (object.ReferenceEquals(policySource,
                context.PersistentPolicies))
            {
                return;
            }

            var cacheLifetime =
                lifetimePolicy as CacheLifetimeManager;
            if (cacheLifetime == null)
            {
                return;
            }

            var childLifetime = cacheLifetime.Clone();

            context
                .PersistentPolicies
                .Set<ILifetimePolicy>(childLifetime,
                    context.BuildKey);
            context.Lifetime.Add(childLifetime);
        }
        public override void PreBuildUp(IBuilderContext context)
        {
            NamedTypeBuildKey key = context.OriginalBuildKey;

            if (!(key.Type.IsInterface && _typeStacks.ContainsKey(key.Type)))
            {
                return;
            }

            if (null != context.GetOverriddenResolver(key.Type))
            {
                return;
            }

            var stack = new Stack<Type>(_typeStacks[key.Type]);
            object value = null;
            stack.ForEach(type =>
            {
                value = context.NewBuildUp(new NamedTypeBuildKey(type, key.Name));
                var overrides = new DependencyOverride(key.Type, value);
                context.AddResolverOverrides(overrides);
            }
                );

            context.Existing = value;
            context.BuildComplete = true;
        }
 public override Func<IResolutionContext, ProviderDependencyHelper> GetProviderDependencyHelperFactory(IBuilderContext builderContext)
 {
     if (_localConfig != null)
     {
         //NOTE: This must be lazy call because we cannot initialize membership providers now as exceptions will occur
         // because our Hive membersip provider hasn't been initialized yet, plus its a bit more performant.
         return x => new DependencyHelper(
             _localConfig.MembershipProviders.Cast<ProviderElement>(),
             new Lazy<IEnumerable<MembershipProvider>>(() =>
             {
                 var providers = new List<MembershipProvider>();
                 var castedProviders = global::System.Web.Security.Membership.Providers.Cast<MembershipProvider>();
                 //get reference to all membership providers referenced in our config
                 foreach (var m in _localConfig.MembershipProviders.Cast<ProviderElement>())
                 {
                     var found = castedProviders.SingleOrDefault(provider => provider.Name == m.Name);
                     if (found != null)
                     {
                         providers.Add(found);
                     }
                     else
                     {
                         LogHelper.Warn<MembershipDemandBuilder>("Could not load a MembershipProvider with the name " + m.Name);
                     }
                 }
                 return providers;
             }), x.Resolve<ProviderMetadata>(ProviderKey));
     }
     return null;
 }
Example #11
0
            public override void PostBuildUp(IBuilderContext context)
            {
                base.PostBuildUp(context);

                Type targetType = context.Existing.GetType();

                if (!_trackabilityCache.ContainsKey(targetType))
                    _trackabilityCache[targetType] =
                        targetType.GetInterfaces().Contains(typeof(ITrackingAware)) ||
                        targetType.GetProperties().Any(p => p.GetCustomAttributes(true).OfType<TrackableAttribute>().Count() > 0);

                if (_trackabilityCache[targetType])
                {
                    List<StateTracker> trackers = new List<StateTracker>(_container.ResolveAll<StateTracker>());
                    if (_container.IsRegistered<StateTracker>())
                        trackers.Add(_container.Resolve<StateTracker>());

                    foreach (StateTracker tracker in trackers)
                    {
                        var config = tracker.Configure(context.Existing);
                        _customizeConfigAction(config);
                        config.Apply();
                    }
                }
            }
        public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            MockTraceListenerClient createdObject = new MockTraceListenerClient();
            createdObject.traceListener = TraceListenerCustomFactory.Instance.Create(context, name, configurationSource, reflectionCache);

            return createdObject;
        }
        private void ApplyPolicy(IBuilderContext context, object obj, string id)
        {
            if (obj == null)
                return;

            Type type = obj.GetType();
            IMethodPolicy policy = context.Policies.Get<IMethodPolicy>(type, id);

            if (policy == null)
                return;

            foreach (IMethodCallInfo methodCallInfo in policy.Methods.Values)
            {
                MethodInfo methodInfo = methodCallInfo.SelectMethod(context, type, id);

                if (methodInfo != null)
                {
                    object[] parameters = methodCallInfo.GetParameters(context, type, id, methodInfo);
                    Guard.ValidateMethodParameters(methodInfo, parameters, obj.GetType());

                    if (TraceEnabled(context))
                        TraceBuildUp(context, type, id, Properties.Resources.CallingMethod, methodInfo.Name, ParametersToTypeList(parameters));

                    methodInfo.Invoke(obj, parameters);
                }
            }
        }
        /// <summary>
        /// Initializes the provider and ensures that all configuration can be read
        /// </summary>
        /// <param name="builderContext"></param>
        public override void Initialise(IBuilderContext builderContext)
        {
            Mandate.ParameterNotNull(builderContext, "builderContext");

            var configMain = builderContext.ConfigurationResolver.GetConfigSection(HiveConfigSection.ConfigXmlKey) as HiveConfigSection;

            if (configMain == null)
                throw new ConfigurationErrorsException(
                    string.Format("Configuration section '{0}' not found when building packaging provider '{1}'",
                                  HiveConfigSection.ConfigXmlKey, ProviderKey));

            var config2Rw = configMain.Providers.ReadWriters[ProviderKey] ?? configMain.Providers.Readers[ProviderKey];

            if (config2Rw == null)
                throw new ConfigurationErrorsException(
                    string.Format("No configuration found for persistence provider '{0}'", ProviderKey));

            //get the Hive provider config section
            _localConfig = DeepConfigManager.Default.GetFirstPluginSection<ProviderConfigurationSection>(config2Rw.ConfigSectionKey);

            if (!ValidateProviderConfigSection<MembershipDemandBuilder>(_localConfig, config2Rw))
            {
                CanBuild = false;
                return;
            }

            CanBuild = true;
        }
        /// <summary>
        /// Returns a <see cref="StepScopeResolverPolicy"/> for dependencies in the step scope.
        /// </summary>
        /// <param name="context">the current build context</param>
        /// <param name="dependencyType">the type of dependency</param>
        /// <returns>a <see cref="StepScopeResolverPolicy"/> if the dependency being resolved in is step scope; null otherwise</returns>
        public override IDependencyResolverPolicy GetResolver(IBuilderContext context, Type dependencyType)
        {
            var constructorParameterOperation = context.CurrentOperation as ConstructorArgumentResolveOperation;
            StepScopeDependency dependency;
            if (constructorParameterOperation != null &&
                _constructorParameters.TryGetValue(constructorParameterOperation.ParameterName, out dependency))
            {
                return new StepScopeResolverPolicy(dependency);
            }

            var propertyValueOperation = context.CurrentOperation as ResolvingPropertyValueOperation;
            if (propertyValueOperation != null && _properties.TryGetValue(propertyValueOperation.PropertyName, out dependency))
            {
                return new StepScopeResolverPolicy(dependency);
            }

            var methodParameterOperation = context.CurrentOperation as MethodArgumentResolveOperation;
            if (methodParameterOperation != null && 
                TryGetMethodParameterDependency(
                    new Tuple<string, string>(methodParameterOperation.MethodSignature, methodParameterOperation.ParameterName),
                    out dependency))
            {
                return new StepScopeResolverPolicy(dependency);
            }

            return null;
        }
        private WorkItem GetWorkItem(IBuilderContext context, object item)
        {
            if (item is WorkItem)
                return item as WorkItem;

            return context.Locator.Get<WorkItem>(new DependencyResolutionLocatorKey(typeof(WorkItem), null));
        }
        public override void PreBuildUp(IBuilderContext context)
        {
            if (context.BuildKey.Type == typeof (IUnityContainer))
            {
                return;
            }

            IInstanceInterceptionPolicy policy = FindInterceptorPolicy(context);
            if (null != policy)
            {
                if (policy.GetInterceptor(context).CanIntercept(context.BuildKey.Type))
                {
                    Interception.SetDefaultInterceptorFor(context.BuildKey.Type, policy.GetInterceptor(context));
                }
            }
            else
            {
                if (Interception.Interceptor.CanIntercept(context.BuildKey.Type) &&
                    Interception.Interceptor is IInstanceInterceptor)
                {
                    Interception.SetDefaultInterceptorFor(context.BuildKey.Type,
                        (IInstanceInterceptor) Interception.Interceptor);
                }
            }
            base.PreBuildUp(context);
        }
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="context">The builder context in which the resolver will resolve
        /// dependencies.</param>
        public DependencyResolver(IBuilderContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            this.context = context;
        }
Example #19
0
 public static void SetCurrentOperationToResolvingParameter(string parameterName, string methodSignature, IBuilderContext context)
 {
     Guard.ArgumentNotNull(context, "context");
     context.CurrentOperation = new MethodArgumentResolveOperation(
         context.BuildKey.Type,
         methodSignature, parameterName);
 }
        /// <summary>
        /// Initializes the provider and ensures that all configuration can be read
        /// </summary>
        /// <param name="builderContext"></param>
        public override void Initialise(IBuilderContext builderContext)
        {
            Mandate.ParameterNotNull(builderContext, "builderContext");

            var configMain = builderContext.ConfigurationResolver.GetConfigSection(HiveConfigSection.ConfigXmlKey) as HiveConfigSection;

            if (configMain == null)
                throw new ConfigurationErrorsException(
                    string.Format("Configuration section '{0}' not found when building packaging provider '{1}'",
                                  HiveConfigSection.ConfigXmlKey, ProviderKey));

            var config2Rw = RegistryConfigElement ?? configMain.Providers.ReadWriters[ProviderKey] ?? configMain.Providers.Readers[ProviderKey];

            if (config2Rw == null)
                throw new ConfigurationErrorsException(
                    string.Format("No configuration found for persistence provider '{0}'", ProviderKey));

            //get the Hive provider config section
            _localConfig = DeepConfigManager.Default.GetFirstPluginSection<ProviderConfigurationSection>(config2Rw.ConfigSectionKey);

            if (!ValidateProviderConfigSection<ExamineDemandBuilder>(_localConfig, config2Rw))
            {
                CanBuild = false;
                return;
            }

            var configMgr = DeepConfigManager.Default;

            //get the internal indexer provider
            _internalIndexer = configMgr.GetFirstPluginSetting<ExamineSettings, ProviderSettings>("examine/examine.settings",
                                                                                             x => x.IndexProviders.SingleOrDefault(indexer => indexer.Name == _localConfig.InternalIndexer));
            if (_internalIndexer == null)
            {
                LogHelper.Warn<ExamineDemandBuilder>("Could not load UmbracoInternalIndexer, the configuration section could not be read.");
                CanBuild = false;
                return;
            }
                
            //get the internal searcher provider
            _internalSearcher = configMgr.GetFirstPluginSetting<ExamineSettings, ProviderSettings>("examine/examine.settings",
                                                                                              x => x.SearchProviders.SingleOrDefault(indexer => indexer.Name == _localConfig.InternalSearcher));
            if (_internalSearcher == null)
            {
                LogHelper.Warn<ExamineDemandBuilder>("Could not load UmbracoInternalSearcher, the configuration section could not be read.");
                CanBuild = false;
                return;
            }                

            //get the internal index set to use for the searcher/indexer
            _internalIndexSet = configMgr.GetFirstPluginSetting<IndexSets, IndexSet>("examine/examine.indexes",
                                                                                x => x.SingleOrDefault(set => set.SetName == _localConfig.InternalIndexSet));
            if (_internalIndexSet == null)
            {
                LogHelper.Warn<ExamineDemandBuilder>("Could not load UmbracoInternalIndexSet, the configuration section could not be read.");
                CanBuild = false;
                return;
            }

            CanBuild = true;
        }
 private void InjectProperties(IBuilderContext context, object obj, string id)
 {
     if (obj != null)
     {
         Type typePolicyAppliesTo = obj.GetType();
         IPropertySetterPolicy policy = context.Policies.Get<IPropertySetterPolicy>(typePolicyAppliesTo, id);
         if (policy != null)
         {
             foreach (IPropertySetterInfo info in policy.Properties.Values)
             {
                 PropertyInfo propInfo = info.SelectProperty(context, typePolicyAppliesTo, id);
                 if (propInfo != null)
                 {
                     if (!propInfo.CanWrite)
                     {
                         throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.CannotInjectReadOnlyProperty, new object[] { typePolicyAppliesTo, propInfo.Name }));
                     }
                     object obj2 = info.GetValue(context, typePolicyAppliesTo, id, propInfo);
                     if (obj2 != null)
                     {
                         Guard.TypeIsAssignableFromType(propInfo.PropertyType, obj2.GetType(), obj.GetType());
                     }
                     if (base.TraceEnabled(context))
                     {
                         base.TraceBuildUp(context, typePolicyAppliesTo, id, Resources.CallingProperty, new object[] { propInfo.Name, propInfo.PropertyType.Name });
                     }
                     propInfo.SetValue(obj, obj2, null);
                 }
             }
         }
     }
 }
        public static void SetCurrentOperationToInvokingConstructor(string constructorSignature, IBuilderContext context)
        {
            Guard.ArgumentNotNull(context, "context");

            context.CurrentOperation = new InvokingConstructorOperation(
                context.BuildKey.Type, constructorSignature);
        }
            public override void PreBuildUp(IBuilderContext context)
            {
                var policy = BuildTracking.GetPolicy(context)
                    ?? BuildTracking.SetPolicy(context);

                policy.BuildKeys.Push(context.BuildKey);
            }
        private ValidatorFactory GetValidatorFactory(IBuilderContext context)
        {
            var validationSpecificationSource = ValidationSource(context);

            if(validationSpecificationSource == 0)
            {
                throw new InvalidOperationException(
                    string.Format(CultureInfo.CurrentCulture, 
                    Resources.InvalidValidationSpecificationSource, validationSpecificationSource));
            }

            if(validationSpecificationSource == ValidationSpecificationSource.All)
            {
                return context.NewBuildUp<ValidatorFactory>();
            }

            var factories = new List<ValidatorFactory>();

            if((validationSpecificationSource & ValidationSpecificationSource.Attributes) != 0)
            {
                factories.Add(context.NewBuildUp<AttributeValidatorFactory>());
            }
            if((validationSpecificationSource & ValidationSpecificationSource.Configuration) != 0)
            {
                factories.Add(context.NewBuildUp<ConfigurationValidatorFactory>());
            }
            if((validationSpecificationSource & ValidationSpecificationSource.DataAnnotations) != 0)
            {
                factories.Add(context.NewBuildUp<ValidationAttributeValidatorFactory>());
            }

            return new CompositeValidatorFactory(GetInstrumentationProvider(context), factories);
        }
        /// <summary>
        /// Implementation of <see cref="IBuilderStrategy.BuildUp"/>. Sets the property values.
        /// </summary>
        /// <param name="context">The build context.</param>
        /// <param name="typeToBuild">The type being built.</param>
        /// <param name="existing">The object on which to inject property values.</param>
        /// <param name="idToBuild">The ID of the object being built.</param>
        /// <returns>The built object.</returns>
        public override object BuildUp(IBuilderContext context, Type typeToBuild, object existing, string idToBuild)
        {
            if (existing != null)
                InjectProperties(context, existing, idToBuild);

            return base.BuildUp(context, typeToBuild, existing, idToBuild);
        }
        /// <summary>
        /// Implementation of <see cref="IBuilderStrategy.BuildUp"/>.
        /// </summary>
        /// <param name="context">The build context.</param>
        /// <param name="typeToBuild">The type of the object being built.</param>
        /// <param name="existing">The existing instance of the object.</param>
        /// <param name="idToBuild">The ID of the object being built.</param>
        /// <returns>The built object.</returns>
        public override object BuildUp(
			IBuilderContext context, Type typeToBuild, object existing, string idToBuild)
        {
            IBuildPlan buildPlan = GetPlanFromContext(context, typeToBuild, idToBuild);
            existing = buildPlan.BuildUp(context, typeToBuild, existing, idToBuild);
            return base.BuildUp(context, typeToBuild, existing, idToBuild);
        }
        /// <summary>
        /// Called during the chain of responsibility for a build operation. The
        ///             PreBuildUp method is called when the chain is being executed in the
        ///             forward direction.
        /// </summary>
        /// <param name="context">Context of the build operation.</param>
        public override void PreBuildUp(IBuilderContext context)
        {
            if (context == null) throw new ArgumentNullException("context");

            var key = context.BuildKey;

            if(!RequestIsForValidatorOfT(key)) return;

            var typeToValidate = TypeToValidate(key.Type);
            var rulesetName = key.Name;

            var validatorFactory = GetValidatorFactory(context);

            Validator validator;

            if(string.IsNullOrEmpty(rulesetName))
            {
                validator = validatorFactory.CreateValidator(typeToValidate);
            }
            else
            {
                validator = validatorFactory.CreateValidator(typeToValidate, rulesetName);
            }

            context.Existing = validator;
            context.BuildComplete = true;
        }
 /// <summary>
 /// Get the value for a dependency.
 /// </summary>
 /// <param name="context">Current build context.</param>
 /// <returns>
 /// The value for the dependency.
 /// </returns>
 public object Resolve(IBuilderContext context)
 {
     return context.NewBuildUp(new NamedTypeBuildKey(validatorType, ruleSet),
         newContext => newContext.Policies.Set(
             new ValidationSpecificationSourcePolicy(validationSource),
             new NamedTypeBuildKey(validatorType, ruleSet)));
 }
        public void Build(IContainerBuilder containerBuilder, IBuilderContext context)
        {
            containerBuilder.For<MapResolverContext>().KnownAsSelf().ScopedAs.Singleton();

            // register the model mappers
            containerBuilder.For<RenderTypesModelMapper>()
                .KnownAs<AbstractMappingEngine>()
                .WithMetadata<TypeMapperMetadata, bool>(x => x.MetadataGeneratedByMapper, true)
                .ScopedAs.Singleton();

            containerBuilder
                .For<FrameworkModelMapper>()
                .KnownAs<AbstractMappingEngine>()
                .WithMetadata<TypeMapperMetadata, bool>(x => x.MetadataGeneratedByMapper, true)
                .ScopedAs.Singleton();

            //register model mapper for security model objects
            containerBuilder
                .For<SecurityModelMapper>()
                .KnownAs<AbstractMappingEngine>()
                .WithMetadata<TypeMapperMetadata, bool>(x => x.MetadataGeneratedByMapper, true)
                .ScopedAs.Singleton();

            //register model mapper for web model objects
            containerBuilder
                .For<CmsModelMapper>()
                .KnownAs<AbstractMappingEngine>()
                .WithMetadata<TypeMapperMetadata, bool>(x => x.MetadataGeneratedByMapper, true)
                .ScopedAs.Singleton();
        }
        /// <summary>
        /// See <see cref="IPropertySetterInfo.SelectProperty"/> for more information.
        /// </summary>
        public PropertyInfo SelectProperty(IBuilderContext context, Type type, string id)
        {
            if (prop != null)
                return prop;

            return type.GetProperty(name);
        }
Example #31
0
 public Type GetParameterType(IBuilderContext context)
 {
     return(serviceType);
 }
        IFunctionProvider IAssembler <IFunctionProvider, FunctionProviderData> .Assemble(IBuilderContext context, FunctionProviderData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            var data = objectConfiguration as RazorFunctionProviderData;

            if (data == null)
            {
                throw new ArgumentException("Expected configuration to be of type RazorFunctionProviderData", "objectConfiguration");
            }

            return(new RazorFunctionProvider(data.Name, data.Directory));
        }
Example #33
0
 public override object BuildUp(IBuilderContext context, Type t, object existing, string id)
 {
     WasRun = true;
     return(existing);
 }
 public void PostBuildUp(IBuilderContext context, object pre = null)
 {
     throw new NotImplementedException();
 }
 object IBuilderStrategy.PreBuildUp(IBuilderContext context)
 {
     throw new NotImplementedException();
 }
 public void PostBuildUp(IBuilderContext context)
 {
     throw new NotImplementedException();
 }
Example #37
0
 /// <summary>
 /// See <see cref="ReflectionStrategy{T}.GetMembers"/> for more information.
 /// </summary>
 protected override IEnumerable <IReflectionMemberInfo <MethodInfo> > GetMembers(IBuilderContext context, Type typeToBuild,
                                                                                 object existing, string idToBuild)
 {
     foreach (MethodInfo method in typeToBuild.GetMethods())
     {
         yield return(new ReflectionMemberInfo <MethodInfo>(method));
     }
 }
 public void SetUp()
 {
     context         = new MockBuilderContext();
     reflectionCache = new ConfigurationReflectionCache();
 }
Example #39
0
 /// <summary>
 /// Implementation of <see cref="IParameter.GetValue"/>.
 /// </summary>
 /// <param name="context">The build context.</param>
 /// <returns>The parameter's value.</returns>
 public override object GetValue(IBuilderContext context)
 {
     return(value);
 }
Example #40
0
 private IBuildPlanCreatorPolicy GetPlanCreator(IBuilderContext context)
 {
     return(context.Policies.Get <IBuildPlanCreatorPolicy>(null));
 }
 public void SetUp()
 {
     context            = new MockBuilderContext();
     reflectionCache    = new ConfigurationReflectionCache();
     traceListenerCache = TraceListenerCustomFactory.CreateTraceListenerCache(3);
 }
Example #42
0
 public IHooklessElementProvider Assemble(IBuilderContext context, HooklessElementProviderData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
 {
     return(new PageElementProvider());
 }
 public override object BuildUp(IBuilderContext context, Type t, object existing, string id)
 {
     WasRun       = true;
     IncomingType = t;
     return(null);
 }
Example #44
0
 public override void PreBuildUp(IBuilderContext context)
 {
     base.PreBuildUp(context);
     existing = context.Existing;
 }
 /// <summary>
 /// Gets the provider dependency helper factory. If a provider requires dependencies with a specific registration key, use this delegate to register a <see cref="ProviderDependencyHelper"/> with the appropriate
 /// keyed dependencies. Otherwise, if this method returns null, <see cref="ProviderDemandRunner"/> will register a <see cref="NullProviderDependencyHelper"/> in its place.
 /// </summary>
 /// <param name="builderContext">The builder context.</param>
 /// <returns></returns>
 public abstract Func <IResolutionContext, ProviderDependencyHelper> GetProviderDependencyHelperFactory(IBuilderContext builderContext);
 public abstract ResolverOverride[] ExtractResolverOverrides(IBuilderContext context);
 /// <summary>
 /// Initialises the provider dependency builder. This method is run by <see cref="Umbraco.Hive.DependencyManagement.ProviderDemandRunner"/> prior to it calling <see cref="Build(Umbraco.Framework.DependencyManagement.IContainerBuilder,Umbraco.Framework.DependencyManagement.IBuilderContext)"/>.
 /// </summary>
 /// <param name="builderContext">The builder context.</param>
 public abstract void Initialise(IBuilderContext builderContext);
 public object BuildUp(IBuilderContext context, Type typeToBuild, object existing, string id)
 {
     return(_builtObject);
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="context"></param>
 public void BuildUp(IBuilderContext context)
 {
     buildMethod(context);
 }
 /// <summary>
 /// Gets the provider bootstrapper factory. The <see cref="AbstractProviderDependencyBuilder"/> will use this to register the <see cref="AbstractProviderBootstrapper"/> against the ProviderKey.
 /// </summary>
 /// <param name="builderContext">The builder context.</param>
 /// <returns></returns>
 public abstract Func <IResolutionContext, AbstractProviderBootstrapper> GetProviderBootstrapperFactory(IBuilderContext builderContext);
Example #51
0
 public static void SetCurrentOperationToInvokingMethod(string methodSignature, IBuilderContext context)
 {
     Guard.ArgumentNotNull(context, "context");
     context.CurrentOperation = new InvokingMethodOperation(context.BuildKey.Type, methodSignature);
 }
 /// <summary>Builds the dependency demands required by this implementation. </summary>
 /// <param name="containerBuilder">The <see cref="IContainerBuilder"/> .</param>
 /// <param name="context">The context for this building session containing configuration etc.</param>
 public abstract void Build(IContainerBuilder containerBuilder, IBuilderContext context);
Example #53
0
 private void BuildUpExistingObject(IBuilderContext context, Type typeToBuild, object existing, string idToBuild)
 {
     RegisterObject(context, typeToBuild, existing, idToBuild);
 }
        public override void Build(IContainerBuilder containerBuilder, IBuilderContext context)
        {
            Mandate.ParameterNotNull(containerBuilder, "containerBuilder");
            Mandate.ParameterNotNull(context, "context");

            var configMgr = DeepConfigManager.Default;

            var configMain = context.ConfigurationResolver
                             .GetConfigSection(HiveConfigurationSection.ConfigXmlKey) as HiveConfigurationSection;

            if (configMain == null)
            {
                throw new ConfigurationErrorsException(
                          string.Format("Configuration section '{0}' not found when building packaging provider '{1}'",
                                        HiveConfigurationSection.ConfigXmlKey, ProviderKey));
            }

            var readWriteConfig = configMain.AvailableProviders.ReadWriters[ProviderKey] ?? configMain.AvailableProviders.Readers[ProviderKey];

            if (readWriteConfig == null)
            {
                throw new ConfigurationErrorsException(
                          string.Format("No configuration found for persistence provider '{0}'", ProviderKey));
            }


            var localConfig = DeepConfigManager
                              .Default
                              .GetWebSettings <ProviderConfigurationSection, ProviderConfigurationSection>(readWriteConfig.ConfigSectionKey, x => x, "~/App_Plugins")
                              .First();

            if (localConfig == null)
            {
                throw new ConfigurationErrorsException(
                          "Unable to resolve the configuration for the FileSystem repository");
            }

            //TODO: Fix hard-coded plugin folder path --Aaron
            var supportedExtensions =
                configMgr.GetWebSetting <ProviderConfigurationSection, string>(readWriteConfig.ConfigSectionKey,
                                                                               x => x.SupportedExtensions, "~/App_Plugins");
            var rootPath = configMgr.GetWebSetting <ProviderConfigurationSection, string>(readWriteConfig.ConfigSectionKey,
                                                                                          x => x.RootPath, "~/App_Plugins");
            var excludeExtensions = configMgr.GetWebSetting <ProviderConfigurationSection, string>(readWriteConfig.ConfigSectionKey,
                                                                                                   x => x.ExcludeExetensions, "~/App_Plugins");

            if (!rootPath.EndsWith("/"))
            {
                rootPath = rootPath + "/";
            }

            containerBuilder
            .ForFactory(x => new ProviderBootstrapper(localConfig))
            .Named <AbstractProviderBootstrapper>(ProviderKey)
            .ScopedAs.Singleton();

            containerBuilder
            .ForFactory(c => new DataContextFactory(
                            supportedExtensions,
                            c.Resolve <HttpContextBase>().Server.MapPath(rootPath),
                            rootPath,
                            excludeExtensions)
                        )
            .Named <AbstractDataContextFactory>(ProviderKey)
            .ScopedAs.NewInstanceEachTime();

            containerBuilder
            .For <ReadWriteUnitOfWorkFactory>()
            .Named <IReadOnlyUnitOfWorkFactory>(ProviderKey)
            .ScopedAs.Singleton();

            containerBuilder
            .For <ReadWriteUnitOfWorkFactory>()
            .Named <IReadWriteUnitOfWorkFactory>(ProviderKey)
            .ScopedAs.Singleton();
        }
 public override object TearDown(IBuilderContext context, object item)
 {
     UnbuildWasRun = true;
     return(base.TearDown(context, AppendString(item)));
 }
Example #56
0
 public static void SetCurrentOperationToResolvingParameter(string parameterName, string methodSignature, IBuilderContext context)
 {
     Guard.ArgumentNotNull(context, "context");
     context.CurrentOperation = new MethodArgumentResolveOperation(
         context.BuildKey.Type,
         methodSignature, parameterName);
 }
Example #57
0
 private static Type GetTheTypeFromTheBuilderContext(IBuilderContext context)
 {
     return((context.OriginalBuildKey).Type);
 }
        /// <summary>
        /// Helper method used by generated IL to look up a dependency resolver based on the given key.
        /// </summary>
        /// <param name="context">Current build context.</param>
        /// <param name="dependencyType">Type of the dependency being resolved.</param>
        /// <param name="resolver">The configured resolver.</param>
        /// <returns>The found dependency resolver.</returns>
        public static IResolverPolicy GetResolver(IBuilderContext context, Type dependencyType, IResolverPolicy resolver)
        {
            var overridden = (context ?? throw new ArgumentNullException(nameof(context))).GetOverriddenResolver(dependencyType);

            return(overridden ?? resolver);
        }
 public void SetUp()
 {
     AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory);
     context         = new BuilderContext(new StrategyChain(), null, null, new PolicyList(), null, null);
     reflectionCache = new ConfigurationReflectionCache();
 }
 public override object BuildUp(IBuilderContext context, Type t, object existing, string id)
 {
     BuildWasRun = true;
     return(base.BuildUp(context, t, AppendString(existing), id));
 }