public static class UnityWebActivator
{
/// <summary>Integrates Unity when the application starts.</summary>
public static void Start()
{
var container = UnityConfig.GetConfiguredContainer();
FilterProviders.Providers.Remove(FilterProviders.Providers.OfType<FilterAttributeFilterProvider>().First());
FilterProviders.Providers.Add(new UnityFilterAttributeFilterProvider(container));
DependencyResolver.SetResolver(new UnityDependencyResolver(container));
Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(UnityPerRequestHttpModule));
}
}
public static class UnityContainerMvcExtensions
{
public static void RegisterGlobalActionFilter<T>(this IUnityContainer container)
where T : IActionFilter
{
container.RegisterType<T>(new PerRequestLifetimeManager());
GlobalFilters.Filters.Add(new ActionFilterWrapperAttribute(typeof(T)));
}
}
GlobalFilters.Add(new FilterWithCollaborators(new LoggingCollaborator(), new UnitofWork()));
public static class UnityContainerWebApiExtensions
{
public static void RegisterGlobalActionFilter<T>(this IUnityContainer container)
where T : IActionFilter
{
container.RegisterType<T>(new PerRequestLifetimeManager());
GlobalConfiguration.Configuration.Filters.Add(new ActionFilterWrapperAttribute(typeof(T)));
}
}
public static class UnityWebApiActivator
{
/// <summary>Integrates Unity when the application starts.</summary>
public static void Start()
{
var resolver = new UnityHierarchicalDependencyResolver(UnityConfig.GetConfiguredContainer());
var defaultProviders = GlobalConfiguration.Configuration.Services.GetFilterProviders();
GlobalConfiguration.Configuration.Services.Remove(typeof(IFilterProvider), defaultProviders.First(f => f is ActionDescriptorFilterProvider));
GlobalConfiguration.Configuration.Services.Add(typeof(IFilterProvider), new WebApiUnityFilterProvider(UnityConfig.GetConfiguredContainer()));
GlobalConfiguration.Configuration.DependencyResolver = resolver;
}
}