/// <summary> /// Registers the specified name. /// </summary> /// <typeparam name="TService">The type of the service.</typeparam> /// <param name="name">The name.</param> /// <param name="factory">The factory.</param> /// <param name="isAlwaysCreatingNew">if set to <c>true</c> [always new].</param> /// <returns> /// ServiceLocatorEntryStruct<TService>. /// </returns> public ServiceLocatorEntryStruct <TService> Register <TService>(string name, Func <object, TService> factory, bool isAlwaysCreatingNew = true) { name = name ?? ""; ServiceLocatorEntryStruct <TService> rval; if (isAlwaysCreatingNew) { ServiceTypedCache <TService> .dic[name] = rval = new ServiceLocatorEntryStruct <TService>(name) { ServiceFactory = factory, CacheType = CacheType.Factory }; } else { ServiceTypedCache <TService> .dic[name] = rval = new ServiceLocatorEntryStruct <TService>(name) { ServiceFactory = factory, CacheType = CacheType.LazyInstance }; } if (!disposeActions.ContainsKey(typeof(TService))) { disposeActions[typeof(TService)] = () => ServiceTypedCache <TService> .dic.Clear(); } return(rval); }
public ServiceLocatorEntryStruct <TService> Register <TService>(string name, Func <object, Task <TService> > asyncFactory, bool alwaysNew = true) { name = name ?? ""; ServiceLocatorEntryStruct <TService> rval; if (alwaysNew) { ServiceTypedCache <TService> .dic[name] = rval = new ServiceLocatorEntryStruct <TService>(name) { CacheType = CacheType.AsyncFactory, AsyncServiceFactory = asyncFactory }; } else { ServiceTypedCache <TService> .dic[name] = rval = new ServiceLocatorEntryStruct <TService>(name) { CacheType = CacheType.AsyncLazyInstance, AsyncServiceFactory = asyncFactory }; } if (!disposeActions.ContainsKey(typeof(TService))) { disposeActions[typeof(TService)] = () => ServiceTypedCache <TService> .dic.Clear(); } return(rval); }
public ServiceLocatorEntryStruct <TService> Register(string name, TService instance) { name = name ?? ""; return(dic[name] = new ServiceLocatorEntryStruct <TService>(name) { CacheType = CacheType.Instance, ServiceInstance = instance, }); }
public bool IsAsync <TService>(string name = "") { name = name ?? ""; ServiceLocatorEntryStruct <TService> entry = null; if (ServiceTypedCache <TService> .dic.TryGetValue(name, out entry)) { return (entry.GetIsValueCreated()); } else { throw new ArgumentException("No such key"); } }
public bool HasInstance <TService>(string name = "") { name = name ?? ""; ServiceLocatorEntryStruct <TService> entry = null; if (ServiceTypedCache <TService> .dic.TryGetValue(name, out entry)) { return (entry.GetIsValueCreated()); } else { return(false); } }
public TService Resolve <TService>(string name = null, object paremeters = null) { name = name ?? ""; var subdic = ServiceTypedCache <TService> .dic; ServiceLocatorEntryStruct <TService> entry = null; if (subdic.TryGetValue(name, out entry)) { return(entry.GetService(paremeters)); } else { return(default(TService)); } }
/// <summary> /// resolve as an asynchronous operation. /// </summary> /// <param name="name">The name.</param> /// <param name="parameter">The parameter.</param> /// <returns>Task<TService>.</returns> public async Task <TService> ResolveAsync(string name = null, object parameter = null) { name = name ?? ""; var subdic = dic; ServiceLocatorEntryStruct <TService> entry = null; if (subdic.TryGetValue(name, out entry)) { return(await entry.GetServiceAsync()); } else { return(await Task.FromResult(default(TService))); } }
public async Task <TService> ResolveAsync <TService>(string name = null, object paremeter = null) { name = name ?? ""; var subdic = ServiceTypedCache <TService> .dic; ServiceLocatorEntryStruct <TService> entry = null; if (subdic.TryGetValue(name, out entry)) { return(await entry.GetServiceAsync()); } else { //#if SILVERLIGHT_5||WINDOWS_PHONE_7 // return await T.askEx.FromResult(default(TService)); //#else // return await T.ask.FromResult(default(TService)); //#endif return(await TaskExHelper.FromResult(default(TService))); } }
public ServiceLocatorEntryStruct <TService> Register(string name, Func <object, Task <TService> > asyncFactory, bool alwaysNew = true) { name = name ?? ""; if (alwaysNew) { return(dic[name] = new ServiceLocatorEntryStruct <TService>(name) { CacheType = CacheType.AsyncFactory, AsyncServiceFactory = asyncFactory }); } else { return(dic[name] = new ServiceLocatorEntryStruct <TService>(name) { CacheType = CacheType.AsyncLazyInstance, AsyncServiceFactory = asyncFactory }); } }
/// <summary> /// Registers the specified name. /// </summary> /// <param name="name">The name.</param> /// <param name="factory">The factory.</param> /// <param name="isAlwaysCreatingNew">if set to <c>true</c> [always new].</param> /// <returns>ServiceLocatorEntryStruct<TService>.</returns> public ServiceLocatorEntryStruct <TService> Register(string name, Func <object, TService> factory, bool isAlwaysCreatingNew = true) { name = name ?? ""; if (isAlwaysCreatingNew) { return(dic[name] = new ServiceLocatorEntryStruct <TService>(name) { CacheType = CacheType.Factory, ServiceFactory = factory }); } else { return(dic[name] = new ServiceLocatorEntryStruct <TService>(name) { CacheType = CacheType.LazyInstance, ServiceFactory = factory }); } }