public static TServiceGroupItem Get <TServiceGroup, TServiceGroupItem>(IServiceRegistry container, LifeTimeEnum lifetime = LifeTimeEnum.New) where TServiceGroup : class where TServiceGroupItem : class, TServiceGroup { return(Get <TServiceGroup, TServiceGroupItem>((IServiceContainer)container, lifetime)); }
public IInstanceIdentification CreateAutoServiceGroupIdentification <TServiceGroup, TServiceGroupItem, TImp>( LifeTimeEnum lifeTime = LifeTimeEnum.New) where TServiceGroup : class where TServiceGroupItem : class, TServiceGroup where TImp : class, TServiceGroupItem { return(new AutoServiceGroupItemInstanceIdentification <TServiceGroup, TServiceGroupItem, TImp>(lifeTime)); }
public AutoServiceInstanceIdentification(LifeTimeEnum lifeTime = LifeTimeEnum.New) { _serviceType = typeof(TService); _lifeTime = lifeTime; StringBuilder typeIdBuilder = new StringBuilder(); typeIdBuilder.AppendFormat("{0}||{1}", _serviceType.Name, lifeTime); this._typeId = typeIdBuilder.ToString(); }
private static ILifetime GetLifeTime(LifeTimeEnum lifeTime) { switch (lifeTime) { case LifeTimeEnum.Scoped: return(new PerScopeLifetime()); case LifeTimeEnum.Singleton: return(new PerContainerLifetime()); case LifeTimeEnum.New: return(new PerRequestLifeTime()); default: throw ExceptionHelper.SwitchCaseValueNotSupportedException("Lifetime type does not supported.", lifeTime); } }
public IAutoServiceGroupItemInstanceIdentification FindByService <TServiceGroup, TServiceGroupItem>( LifeTimeEnum lifeTime) where TServiceGroup : class where TServiceGroupItem : class, TServiceGroup { int index; int count = this.Count; IAutoServiceGroupItemInstanceIdentification current = null; for (index = 0; index < count; index++) { current = this[index]; if (current.IsRegisteredFor <TServiceGroup, TServiceGroupItem>(lifeTime)) { return(current); } } return(null); }
public AutoServiceGroupItemInstanceIdentification(LifeTimeEnum lifeTime = LifeTimeEnum.New) { this._serviceGroupType = typeof(TServiceGroup); this._serviceGroupItemType = typeof(TServiceGroupItem); this._implementationType = typeof(TImp); this._lifeTime = lifeTime; StringBuilder typeIdBuilder = new StringBuilder(); #if DEBUG typeIdBuilder.AppendFormat("{0}||{1}||{2}", _serviceGroupType.AssemblyQualifiedName, _serviceGroupItemType.AssemblyQualifiedName, lifeTime); //typeIdBuilder.AppendFormat("{0}||{1}||{2}", _serviceGroupType.Name, _serviceGroupItemType.Name, lifeTime); #endif #if !DEBUG typeIdBuilder.AppendFormat("{0}||{1}||{2}", _serviceGroupType.AssemblyQualifiedName, _serviceGroupItemType.AssemblyQualifiedName, lifeTime); #endif this._typeId = typeIdBuilder.ToString(); }
public RegisterInfo(LifeTimeEnum lifeTimeType) { this.LifeTimeType = lifeTimeType; }
public bool IsRegisteredFor <TRequestedService>(LifeTimeEnum lifeTime = LifeTimeEnum.New) where TRequestedService : class { return(_serviceType == typeof(TRequestedService) && _lifeTime == lifeTime); }
public bool IsRegisteredFor <TRequestedServiceGroup, TRequestedServiceGroupItem>(LifeTimeEnum lifeTime = LifeTimeEnum.New) where TRequestedServiceGroup : class where TRequestedServiceGroupItem : class, TRequestedServiceGroup { return(this._serviceGroupType == typeof(TRequestedServiceGroup) && this._serviceGroupItemType == typeof(TRequestedServiceGroupItem) && this._lifeTime == lifeTime); }
public static TServiceGroupItem Get <TServiceGroup, TServiceGroupItem>(IServiceContainer container, LifeTimeEnum lifetime = LifeTimeEnum.New) where TServiceGroup : class where TServiceGroupItem : class, TServiceGroup { AutoServiceGroupItemInstanceIdentificationList foundIdentifiers = new AutoServiceGroupItemInstanceIdentificationList(container.GetAllInstances <IInstanceIdentification>()); if (foundIdentifiers.Count == 0) { return(null); } IInstanceIdentification foundIdentifier = foundIdentifiers.FindByService <TServiceGroup, TServiceGroupItem>(lifetime); if (foundIdentifier != null) { return(container.GetInstance <TServiceGroup>(foundIdentifier.GetTypeId()) as TServiceGroupItem); } return(null); }
public static void Reg <TDomainModelServiceFamily, TDomainModelService, TDomainModelImp>(IServiceRegistry registry, LifeTimeEnum lifeTime = LifeTimeEnum.New) where TDomainModelServiceFamily : class, IDomainEntity where TDomainModelService : class, TDomainModelServiceFamily where TDomainModelImp : class, TDomainModelService, new() { IServiceContainer iocc = registry as IServiceContainer; IOCH.Reg <TDomainModelServiceFamily, TDomainModelService, TDomainModelImp>(iocc, () => iocc.GetInstance <IEntityModelFactory>().Create <TDomainModelImp, TDomainModelImp>(iocc), lifeTime: lifeTime); }
public static void Reg <TServiceGroup, TServiceGroupItem, TImp>(IServiceContainer container, Func <TServiceGroupItem> serviceFactory = null, string serviceName = null, LifeTimeEnum lifeTime = LifeTimeEnum.New) where TServiceGroup : class where TServiceGroupItem : class, TServiceGroup where TImp : class, TServiceGroupItem { if (serviceName == null) { IAutoServiceGroupItemInstanceIdentification identifier = container.GetInstance <IInstanceIdentificationFactory>() .CreateAutoServiceGroupIdentification <TServiceGroup, TServiceGroupItem, TImp>(lifeTime) as IAutoServiceGroupItemInstanceIdentification; string autoName = identifier.GetTypeId(); System.Diagnostics.Debug.WriteLine(autoName); if (serviceFactory == null) { if (lifeTime == LifeTimeEnum.New) { container.Register <TServiceGroup, TImp>(autoName); } else { container.Register <TServiceGroup, TImp>(autoName, GetLifeTime(lifeTime)); } } else { if (lifeTime == LifeTimeEnum.New) { container.Register <TServiceGroup>(factory => serviceFactory(), autoName); } else { container.Register <TServiceGroup>(factory => serviceFactory(), autoName, GetLifeTime(lifeTime)); } } container.Register <ILFW <TServiceGroup> >( factory => new LFW <TServiceGroupItem>( () => factory.GetInstance <TServiceGroup>(autoName) as TServiceGroupItem, identifier), autoName, new PerContainerLifetime()); } else { if (lifeTime == LifeTimeEnum.New) { container.Register <TServiceGroup, TImp>(serviceName); } else { container.Register <TServiceGroup, TImp>(serviceName, GetLifeTime(lifeTime)); } } }
public static void Reg <TServiceGroup, TServiceGroupItem, TImp>(IServiceRegistry registry, Func <TServiceGroupItem> serviceFactory = null, string serviceName = null, LifeTimeEnum lifeTime = LifeTimeEnum.New) where TServiceGroup : class where TServiceGroupItem : class, TServiceGroup where TImp : class, TServiceGroupItem { Reg <TServiceGroup, TServiceGroupItem, TImp>((IServiceContainer)registry, serviceFactory, serviceName, lifeTime); }
public RegisterInfo(string name, LifeTimeEnum lifeTimeType) { this.Name = name; this.LifeTimeType = lifeTimeType; }
public IInstanceIdentification CreateAutoServiceIdentification <TService>(LifeTimeEnum lifeTime = LifeTimeEnum.New) where TService : class { return(new AutoServiceInstanceIdentification <TService>(lifeTime)); }
public LifeTime() { this.Type = LifeTimeEnum.transient; }