public static IEntityViewService <T> GetEntityViewService <T>(IServiceFactory serviceFactory) where T : new() { if (viewServiceCache.ContainsKey(typeof(T))) { return((IEntityViewService <T>)viewServiceCache[typeof(T)]); } foreach (PropertyInfo property in typeof(IServiceFactory).GetProperties()) { if (typeof(IEntityViewService <T>).IsAssignableFrom(property.PropertyType)) { IEntityViewService <T> viewService = (IEntityViewService <T>)property.GetValue(serviceFactory, null); viewServiceCache[typeof(T)] = viewService; return(viewService); } } viewServiceCache[typeof(T)] = null; return(null); }
public static IEntityViewService GetEntityViewService(IServiceFactory serviceFactory, Type entityType) { if (viewServiceCache.ContainsKey(entityType)) { return((IEntityViewService)viewServiceCache[entityType]); } Type entityServiceType = typeof(IEntityViewService <>).MakeGenericType(entityType); foreach (PropertyInfo property in typeof(IServiceFactory).GetProperties()) { if (entityServiceType.IsAssignableFrom(property.PropertyType)) { IEntityViewService viewService = (IEntityViewService)property.GetValue(serviceFactory, null); viewServiceCache[entityType] = viewService; return(viewService); } } viewServiceCache[entityType] = null; return(null); }