2015-12-20 17:09:46 +01:00
|
|
|
|
using System.Reflection;
|
2015-01-21 12:48:08 +11:00
|
|
|
|
using System.Web.Http.Controllers;
|
|
|
|
|
|
using System.Web.Mvc;
|
2015-12-20 17:09:46 +01:00
|
|
|
|
using LightInject;
|
2015-01-21 12:48:08 +11:00
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
|
2015-12-20 17:09:46 +01:00
|
|
|
|
namespace Umbraco.Web
|
2015-01-21 12:48:08 +11:00
|
|
|
|
{
|
|
|
|
|
|
internal static class LightInjectExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Registers all IControllers using the PluginManager for scanning and caching found instances for the calling assembly
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="container"></param>
|
|
|
|
|
|
/// <param name="pluginManager"></param>
|
|
|
|
|
|
public static void RegisterMvcControllers(this IServiceRegistry container, PluginManager pluginManager)
|
|
|
|
|
|
{
|
|
|
|
|
|
var types = pluginManager.ResolveTypes<IController>(specificAssemblies: new[] { Assembly.GetCallingAssembly() });
|
|
|
|
|
|
foreach (var type in types)
|
|
|
|
|
|
{
|
|
|
|
|
|
container.Register(type, new PerRequestLifeTime());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Registers all IHttpController using the PluginManager for scanning and caching found instances for the calling assembly
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="container"></param>
|
|
|
|
|
|
/// <param name="pluginManager"></param>
|
|
|
|
|
|
public static void RegisterApiControllers(this IServiceRegistry container, PluginManager pluginManager)
|
|
|
|
|
|
{
|
|
|
|
|
|
var types = pluginManager.ResolveTypes<IHttpController>(specificAssemblies: new[] { Assembly.GetCallingAssembly() });
|
|
|
|
|
|
foreach (var type in types)
|
|
|
|
|
|
{
|
|
|
|
|
|
container.Register(type, new PerRequestLifeTime());
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|