/// <summary> /// 构造函数 /// </summary> /// <param name="serviceProvider"></param> /// <param name="isRoot"></param> public ObjectContainer(IServiceProvider serviceProvider, bool isRoot = false) { this.typeRelations = TypeRelationCollection.Instance; this.objectIndex = new List <string>(); this.objectFactory = new ObjectFactory(serviceProvider); this.objects = new ConcurrentDictionary <string, object>(); this.recordObjects = new HashSet <string>(); if (isRoot) { ObjectContainer.root = this; } }
public StKServiceCollection(IServiceCollection serviceDescriptors) { relations = new TypeRelationCollection(); foreach (var service in serviceDescriptors) { if (service.ImplementationInstance != null) { var id = relations.Add(service.ServiceType, service.ServiceType, service.Lifetime, instance: service.ImplementationInstance).ID; } else if (service.ImplementationFactory != null) { var id = relations.Add(service.ServiceType, service.ImplementationType ?? service.ServiceType, service.Lifetime, factory: service.ImplementationFactory).ID; } else { var id = relations.Add(service.ServiceType, service.ImplementationType, service.Lifetime, factory: _ => _.CreateInstance(service.ImplementationType)).ID; } } }
/// <summary> /// 构造函数 /// </summary> /// <param name="serviceProvider"></param> public ObjectFactory(IServiceProvider serviceProvider) { this.typeRelations = TypeRelationCollection.Instance; this.serviceProvider = serviceProvider; }
/// <summary> /// 构造函数 /// </summary> public ObjectMap() { this.typeRelations = TypeRelationCollection.Instance; }