public void When_getting_controller_attributes_then_builds_up_instance()
        {
            using (var container = new UnityContainer())
            {
                // Arrange
                var someInstance = new SomeClass();
                container.RegisterInstance<ISomeInterface>(someInstance);
                container.RegisterType<TestFilterAttribute>(new InjectionProperty("Some"));

                var context = new ControllerContext { Controller = new ControllerWithTypeAttribute() };
                var controllerDescriptor = new ReflectedControllerDescriptor(context.Controller.GetType());
                var action = context.Controller.GetType().GetMethod("MyActionMethod");
                var actionDescriptor = new ReflectedActionDescriptor(action, "MyActionMethod", controllerDescriptor);
                var provider = new UnityFilterAttributeFilterProvider(container);

                // Act
                Filter filter = provider.GetFilters(context, actionDescriptor).Single();

                // Assert
                TestFilterAttribute attrib = filter.Instance as TestFilterAttribute;
                Assert.IsNotNull(attrib);
                Assert.AreEqual(FilterScope.Controller, filter.Scope);
                Assert.AreEqual(1234, filter.Order);
                Assert.AreSame(someInstance, attrib.Some);
            }
        }
        public static void PreApplicationStart()
        {
            var filterAttributeFilterProvider = FilterProviders.Providers.OfType<FilterAttributeFilterProvider>().First();
            var unityFilterAttributeFilterProvider = new UnityFilterAttributeFilterProvider(Injector.Default.Container);
            var unityDependencyResolver = new UnityDependencyResolver(Injector.Default.Container);

            FilterProviders.Providers.Remove(filterAttributeFilterProvider);
            FilterProviders.Providers.Add(unityFilterAttributeFilterProvider);
            DependencyResolver.SetResolver(unityDependencyResolver);
        }
        private static void RegisterDependencyResolver()
        {
            var container = new UnityContainer();

            /*
                The UnityDecoratorContainerExtension breaks resolving named type registrations, like:

                container.RegisterType<IMembershipService, ADMembershipService>("ActiveDirectory");
                container.RegisterType<IMembershipService, EFMembershipService>("Internal");
                IMembershipService membershipService = container.Resolve<IMembershipService>(AuthenticationSettings.MembershipService);

                Until this issue is resolved, the following two switch hacks will have to do
            */

            switch (AuthenticationSettings.MembershipService.ToLowerInvariant())
            {
                case "activedirectory":
                    container.RegisterType<IMembershipService, ADMembershipService>();
                    container.RegisterType<IRoleProvider, ADRoleProvider>();
                    container.RegisterType<ITeamRepository, ADTeamRepository>();
                    container.RegisterType<IRepositoryRepository, ADRepositoryRepository>();
                    container.RegisterType<IRepositoryPermissionService, RepositoryPermissionService>();
                    break;
                case "internal":
                    container.RegisterType<IMembershipService, EFMembershipService>();
                    container.RegisterType<IRoleProvider, EFRoleProvider>();
                    container.RegisterType<ITeamRepository, EFTeamRepository>();
                    container.RegisterType<IRepositoryRepository, EFRepositoryRepository>();
                    container.RegisterType<IRepositoryPermissionService, RepositoryPermissionService>();
                    break;
                default:
                    throw new ArgumentException("Missing declaration in web.config", "MembershipService");
            }

            switch (AuthenticationSettings.AuthenticationProvider.ToLowerInvariant())
            {
                case "windows":
                    container.RegisterType<IAuthenticationProvider, WindowsAuthenticationProvider>();
                    break;
                case "cookies":
                    container.RegisterType<IAuthenticationProvider, CookieAuthenticationProvider>();
                    break;
                case "federation":
                    container.RegisterType<IAuthenticationProvider, FederationAuthenticationProvider>();
                    break;
                default:
                    throw new ArgumentException("Missing declaration in web.config", "AuthenticationProvider");
            }

            container.RegisterType<IGitRepositoryLocator, ConfigurationBasedRepositoryLocator>(
                new InjectionFactory((ctr, type, name) => {
                    return new ConfigurationBasedRepositoryLocator(UserConfiguration.Current.Repositories);
                })
            );

            container.RegisterInstance(
                new GitServiceExecutorParams()
                {
                    GitPath = GetRootPath(ConfigurationManager.AppSettings["GitPath"]),
                    GitHomePath = GetRootPath(ConfigurationManager.AppSettings["GitHomePath"]),
                    RepositoriesDirPath = UserConfiguration.Current.Repositories,
                });

            container.RegisterType<IDatabaseResetManager, DatabaseResetManager>();

            if (AppSettings.IsPushAuditEnabled)
            {
                EnablePushAuditAnalysis(container);
            }

            container.RegisterType<IGitService, GitServiceExecutor>();

            DependencyResolver.SetResolver(new UnityDependencyResolver(container));

            var oldProvider = FilterProviders.Providers.Single(f => f is FilterAttributeFilterProvider);
            FilterProviders.Providers.Remove(oldProvider);

            var provider = new UnityFilterAttributeFilterProvider(container);
            FilterProviders.Providers.Add(provider);
        }