示例#1
0
        private void RegisterBluePrintItem(List <SmartServiceDescriptor> smartServiceDescriptors, List <EventSubscriptionDescriptor> eventSubs, Dictionary <Type, MethodInfo[]> methodsCache, HashSet <string> flags, ShellBlueprintDependencyItem item, Type interfaceType)
        {
            SmartServiceDescriptor descriptor = null;

            if (typeof(ISingletonDependency).GetTypeInfo().IsAssignableFrom(interfaceType))
            {
                eventSubs.AddRange(CreateDescriptor(methodsCache, flags, interfaceType, item.Type, ServiceLifetime.Singleton));
                descriptor = ServiceDescriber.Singleton(interfaceType, item.Type, SmartOptions.Append);
                item.Interfaces.Add(new Tuple <Type, ServiceLifetime>(interfaceType, ServiceLifetime.Singleton));
            }
            else if (typeof(ITransientDependency).GetTypeInfo().IsAssignableFrom(interfaceType))
            {
                eventSubs.AddRange(CreateDescriptor(methodsCache, flags, interfaceType, item.Type, ServiceLifetime.Transient));
                descriptor = ServiceDescriber.Transient(interfaceType, item.Type, SmartOptions.Append);
                item.Interfaces.Add(new Tuple <Type, ServiceLifetime>(interfaceType, ServiceLifetime.Transient));
            }
            else
            {
                eventSubs.AddRange(CreateDescriptor(methodsCache, flags, interfaceType, item.Type, ServiceLifetime.Scoped));
                descriptor = ServiceDescriber.Scoped(interfaceType, item.Type, SmartOptions.Append);
                item.Interfaces.Add(new Tuple <Type, ServiceLifetime>(interfaceType, ServiceLifetime.Scoped));
            }

            if (descriptor != null)
            {
                descriptor = this.OnDependencyRegistering(descriptor);
                smartServiceDescriptors.Add(descriptor);
            }
        }
示例#2
0
        private SmartServiceDescriptor OnDependencyRegistering(SmartServiceDescriptor serviceDescriptor)
        {
            DependencySetupEventArgs args = new DependencySetupEventArgs(serviceDescriptor);

            ShellEvents.NotifyDependencyRegistering(_options, args);
            var newDesc = args.ActualDependency ?? args.OriginalDependency;

            return(Object.ReferenceEquals(newDesc, serviceDescriptor) ? serviceDescriptor : SmartServiceDescriptor.Create(newDesc, serviceDescriptor.Options));
        }