Exemple #1
0
        private AutoDIServiceInfo GetServiceInfoFromMap(Type interficie)
        {
            AutoDIServiceInfo result = null;

            if (interficie != null)
            {
                var interfaceTypeName = interficie.FullName;
                if (this.map != null && this.map.ContainsKey(interfaceTypeName))
                {
                    result = this.map[interfaceTypeName];
                }
            }

            return(result);
        }
Exemple #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(AutoDIServiceAttribute)));

            if (interfaces != null)
            {
                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);
        }