using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Web.Http.Controllers; using System.Web.Mvc; using Umbraco.Core; using Umbraco.Core.LightInject; namespace Umbraco.Web.LightInject { internal static class LightInjectExtensions { /// /// Registers all IControllers using the PluginManager for scanning and caching found instances for the calling assembly /// /// /// public static void RegisterMvcControllers(this IServiceRegistry container, PluginManager pluginManager) { var types = pluginManager.ResolveTypes(specificAssemblies: new[] { Assembly.GetCallingAssembly() }); foreach (var type in types) { container.Register(type, new PerRequestLifeTime()); } } /// /// Registers all IHttpController using the PluginManager for scanning and caching found instances for the calling assembly /// /// /// public static void RegisterApiControllers(this IServiceRegistry container, PluginManager pluginManager) { var types = pluginManager.ResolveTypes(specificAssemblies: new[] { Assembly.GetCallingAssembly() }); foreach (var type in types) { container.Register(type, new PerRequestLifeTime()); } } } }