Created
July 13, 2016 07:31
-
-
Save testfirstcoder/a9653beac1fe45c4de689fe07e79b8fd to your computer and use it in GitHub Desktop.
Create filter provider for Unity DI-Container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.Web.Http; | |
using System.Web.Http.Controllers; | |
using System.Web.Http.Filters; | |
using Microsoft.Practices.Unity; | |
using Monads.NET; | |
namespace Infrastructure | |
{ | |
public class UnityFilterProvider : IFilterProvider | |
{ | |
public IEnumerable<FilterInfo> GetFilters(HttpConfiguration configuration, HttpActionDescriptor actionDescriptor) | |
{ | |
return new ActionDescriptorFilterProvider() | |
.GetFilters(configuration, actionDescriptor) | |
.Do(_ => UnityConfig.Container.BuildUp(_.Instance.GetType(), _.Instance)); | |
} | |
} | |
} | |
public static class UnityConfig | |
{ | |
public static IUnityContainer Container { get; } = new UnityContainer(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment