コード例 #1
0
        private static IList <TElement> ResolveRegistrations <TElement>(ref BuilderContext context, RegistrationSet registrations)
        {
            var type = typeof(TElement);
            var list = new List <TElement>();

            for (var i = 0; i < registrations.Count; i++)
            {
                ref var entry = ref registrations[i];
                try
                {
#if NETSTANDARD1_0 || NETCOREAPP1_0
                    if (entry.RegisteredType.GetTypeInfo().IsGenericTypeDefinition)
#else
                    if (entry.RegisteredType.IsGenericTypeDefinition)
#endif
                    { list.Add((TElement)context.Resolve(type, entry.Name)); }
                    else
                    {
                        list.Add((TElement)context.Resolve(type, entry.Name, entry.Registration));
                    }
                }
                catch (ArgumentException ex) when(ex.InnerException is TypeLoadException)
                {
                    // Ignore
                }
            }
コード例 #2
0
        private static object FactoryMethod <TResult>(ref BuilderContext context)
        {
            // Resolve requested type
            var service = (TResult)context.Resolve(typeof(TResult), context.Name);

            // Create Foo
            return(new Foo <TResult>(service));
        }
コード例 #3
0
        /// <summary>
        /// Called during the chain of responsibility for a build operation.  Looks for the <see cref="IBuildKeyMappingPolicy"/>
        /// and if found maps the build key for the current operation.
        /// </summary>
        /// <param name="context">The context for the operation.</param>
        public override void PreBuildUp(ref BuilderContext context)
        {
            var map = ((InternalRegistration)context.Registration).Map;

            if (null != map)
            {
                context.Type = map(context.Type);
            }

            if (!((InternalRegistration)context.Registration).BuildRequired &&
                ((UnityContainer)context.Container).RegistrationExists(context.Type, context.Name))
            {
                context.Existing      = context.Resolve(context.Type, context.Name);
                context.BuildComplete = true;
            }
        }
コード例 #4
0
        /// <summary>
        /// Called during the chain of responsibility for a build operation.  Looks for the <see cref="IBuildKeyMappingPolicy"/>
        /// and if found maps the build key for the current operation.
        /// </summary>
        /// <param name="context">The context for the operation.</param>
        public override void PreBuildUp(ref BuilderContext context)
        {
            var map = ((ImplicitRegistration)context.Registration).Map;

            if (null != map)
            {
                context.Type = map(context.Type);
            }

            if (!((ImplicitRegistration)context.Registration).BuildRequired &&
                ((UnityContainer)context.Container).IsRegistered(ref context))
            {
                // TODO: Optimize call, no need for parameters
                context.Existing      = context.Resolve(context.Type, context.Name);
                context.BuildComplete = true;
            }
        }
コード例 #5
0
 /// <summary>
 /// Interceptor to use.
 /// </summary>
 /// <param name="context">Context for current build operation.</param>
 public IInstanceInterceptor GetInterceptor(ref BuilderContext context)
 {
     return((IInstanceInterceptor)context.Resolve(_type, _name));
 }