Exemplo n.º 1
0
        protected ProducibleServiceEntryBase(Type @interface, string?name, Type implementation, IServiceContainer owner) : base(@interface, name, implementation, owner)
        {
            //
            // Os ellenorzi a tobbit.
            //

            Ensure.Parameter.IsNotNull(implementation, nameof(implementation));

            if ([email protected])
            {
                Factory = ServiceActivator.Get(implementation);
                this.ApplyAspects();
            }
            else
            {
                //
                // Konstruktor validalas csak generikus esetben kell (mert ilyenkor nincs Resolver.Get()
                // hivas). A GetApplicableConstructor() validal valamint mukodik generikusokra is.
                //
                // Generikus esetben az aspektusok a bejegyzes tipizalasakor lesznek alkalmazva.
                //

                implementation.GetApplicableConstructor();
            }
        }
Exemplo n.º 2
0
        protected ProducibleServiceEntryBase(Type @interface, string?name, Type implementation, IReadOnlyDictionary <string, object?> explicitArgs, IServiceContainer owner) : base(@interface, name, implementation, owner)
        {
            //
            // Os ellenorzi a tobbit.
            //

            Ensure.Parameter.IsNotNull(implementation, nameof(implementation));
            Ensure.Parameter.IsNotNull(explicitArgs, nameof(explicitArgs));

            if ([email protected])
            {
                Func <IInjector, IReadOnlyDictionary <string, object?>, object> factoryEx = ServiceActivator.GetExtended(implementation);

                Factory = (injector, _) => factoryEx(injector, explicitArgs !);
                this.ApplyAspects();
            }
            else
            {
                implementation.GetApplicableConstructor();
            }

            ExplicitArgs = explicitArgs;
        }
        private static async Task <Func <IInjector, Type, object, object> > BuildDelegate(Type iface, Type interceptor)
        {
            interceptor = await ProxyFactory.GenerateProxyTypeAsync(iface, interceptor);

            ConstructorInfo ctor = interceptor.GetApplicableConstructor();

            ParameterInfo[] compatibleParamz = ctor
                                               .GetParameters()
                                               .Where(para => para.ParameterType == iface)
                                               .ToArray();

            string targetName = compatibleParamz.Length == 1
                ? compatibleParamz[0].Name
                : "target";

            Func <IInjector, IReadOnlyDictionary <string, object?>, object> factory = ServiceActivator.GetExtended(ctor);

            return((IInjector injector, Type iface, object instance) => factory(injector, new Dictionary <string, object?>
            {
                { targetName, instance }
            }));
        }