示例#1
0
        public void GenerateResolver(GeneratedAssembly generatedAssembly)
        {
            if (_resolverType != null)
            {
                return;                        // got some kind of loop in here we need to short circuit
            }
            if (ErrorMessages.Any() || Dependencies.SelectMany(x => x.ErrorMessages).Any())
            {
                return;
            }

            var typeName = (ServiceType.FullNameInCode() + "_" + Name).Sanitize();


            var buildType = ServiceType.MustBeBuiltWithFunc() || ImplementationType.MustBeBuiltWithFunc()
                ? typeof(object)
                : ServiceType;

            _resolverType = generatedAssembly.AddType(typeName, ResolverBaseType.MakeGenericType(buildType));

            var method = _resolverType.MethodFor("Build");

            var frame = CreateBuildFrame();

            method.Frames.Add(frame);
        }
示例#2
0
        public void GenerateResolver(GeneratedAssembly generatedAssembly)
        {
            if (_resolverType != null)
            {
                return;                        // got some kind of loop in here we need to short circuit
            }
            if (ErrorMessages.Any() || Dependencies.SelectMany(x => x.ErrorMessages).Any())
            {
                return;
            }

            var typeName = (ServiceType.FullNameInCode() + "_" + Name).Sanitize();


            _resolverType = generatedAssembly.AddType(typeName, ResolverBaseType.MakeGenericType(ServiceType));

            foreach (var relatedAssembly in relatedAssemblies())
            {
                generatedAssembly.ReferenceAssembly(relatedAssembly);
            }

            var method = _resolverType.MethodFor("Build");

            var frame = CreateBuildFrame();

            method.Frames.Add(frame);
        }
        protected internal override IEnumerable <Instance> createPlan(ServiceGraph services)
        {
            _inner = services.FindInstance(ServiceType, _instanceKey);
            if (_inner == null)
            {
                throw new InvalidOperationException($"Referenced instance of {ServiceType.FullNameInCode()} named '{_instanceKey}' does not exist");
            }

            _inner.Parent = Parent;
            Lifetime      = _inner.Lifetime;

            yield return(_inner);
        }
示例#4
0
        /// <summary>
        /// If the ServiceType is an open generic type, this method will create a
        /// closed type copy of this PluginFamily
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="decoration"></param>
        /// <param name="templateTypes"></param>
        /// <param name="types"></param>
        /// <returns></returns>
        public ServiceFamily CreateTemplatedClone(Type serviceType, IDecoratorPolicy[] decoration, Type[] templateTypes)
        {
            if (!ServiceType.IsGenericType)
            {
                throw new InvalidOperationException($"{ServiceType.FullNameInCode()} is not an open generic type");
            }

            var instances = _instances.Values.ToArray().Select(x => {
                var clone = x.CloseType(serviceType, templateTypes);
                if (clone == null)
                {
                    return(null);
                }

                clone.Name = x.Name;
                return(clone);
            }).Where(x => x != null).ToArray();

            return(new ServiceFamily(serviceType, decoration, instances));
        }
示例#5
0
        public string GetResolverTypeName()
        {
            var typeName = (ServiceType.FullNameInCode() + "_" + Name).Sanitize();

            return(typeName);
        }
示例#6
0
 public override string ToString()
 {
     return($"{nameof(ServiceType)}: {ServiceType.FullNameInCode()}");
 }
示例#7
0
 public object Resolve(Scope scope)
 {
     throw new LamarException($"Cannot build registered instance {Name} of '{ServiceType.FullNameInCode()}':{Environment.NewLine}{_message}");
 }