Exemplo n.º 1
0
        private AutoDIServiceInfo GetServiceInfoFromMap(Type interficie)
        {
            AutoDIServiceInfo result = null;

            if (interficie == null)
            {
                return(result);
            }

            var interfaceTypeName = interficie.FullName;

            if (_map == null || !_map.ContainsKey(interfaceTypeName))
            {
                return(result);
            }

            return(_map[interfaceTypeName]);
        }
Exemplo n.º 2
0
        public List <AutoDIServiceInfo> GetAssemblyInjetedDependencies(Assembly assembly)
        {
            List <AutoDIServiceInfo> resut = new List <AutoDIServiceInfo>();

            var interfaces = assembly.GetExportedTypes().Where(e => e.IsInterface)
                             .Where(e => e.CustomAttributes.Any(c => c.AttributeType == typeof(AutoDIServiceAttributeAttribute)));

            if (interfaces == null)
            {
                return(resut);
            }

            foreach (var interficie in interfaces)
            {
                var service = this.GetServiceInfoFromMap(interficie);
                if (service == null)
                {
                    var interfaceTypeName      = interficie.FullName;
                    var implementationTypeName = this.GetImplementationTypeFromParameters(interficie);
                    if (string.IsNullOrEmpty(implementationTypeName))
                    {
                        implementationTypeName = this.GetDefaultImplementationType(interficie);
                    }

                    var lifetimeType = ServiceLifetime.Transient;

                    var lifetime = this.GetLifetimeFromParameters(interficie);
                    if (lifetime != null)
                    {
                        lifetimeType = (ServiceLifetime)lifetime;
                    }

                    service = new AutoDIServiceInfo(
                        service: interfaceTypeName,
                        implementation: implementationTypeName,
                        lifetime: lifetimeType);
                    service.ServiceAssembly = assembly;
                }
                resut.Add(service);
            }

            return(resut);
        }