/// <summary> /// This method can be used to resolve and release an object automatically. /// You can use the object in <paramref name="action"/>. /// </summary> /// <typeparam name="T">Type of the object to use</typeparam> /// <param name="iocResolver">IResolver object</param> /// <param name="action">An action that can use the resolved object</param> public static void Using <T>(this IResolver iocResolver, Action <T> action) { using (var wrapper = iocResolver.ResolveAsDisposable <T>()) { action(wrapper.Object); } }
/// <summary> /// This method can be used to resolve and release an object automatically. /// You can use the object in <paramref name="func"/> and return a value. /// </summary> /// <typeparam name="TService">Type of the service to use</typeparam> /// <typeparam name="TReturn">Return type</typeparam> /// <param name="iocResolver">IResolver object</param> /// <param name="func">A function that can use the resolved object</param> public static TReturn Using <TService, TReturn>(this IResolver iocResolver, Func <TService, TReturn> func) { using (var obj = iocResolver.ResolveAsDisposable <TService>()) { return(func(obj.Object)); } }