コード例 #1
0
ファイル: Startup.cs プロジェクト: tmcmil/cset
        private static void RegisterFilterProviders(HttpConfiguration config)
        {
            // Add Unity filters provider
            var providers = config.Services.GetFilterProviders().ToList();
            //config.Services.Add(typeof(System.Web.Http.Filters.IFilterProvider), new Unity.WebApi.WebApiUnityActionFilterProvider(UnityHelpers.GetConfiguredContainer()));
            var container = UnityHelpers.GetConfiguredContainer();

            container.RegisterType <CurrentRequest>(new HierarchicalLifetimeManager());

            container.RegisterType <IOwinContext>(new HierarchicalLifetimeManager(),
                                                  new InjectionFactory(c => c.Resolve <CurrentRequest>().Value.GetOwinContext()));

            config.DependencyResolver = new AspNet.WebApi.UnityHierarchicalDependencyResolver(container);

            var defaultprovider = providers.First(p => p is ActionDescriptorFilterProvider);

            config.Services.Remove(typeof(System.Web.Http.Filters.IFilterProvider), defaultprovider);
        }
コード例 #2
0
        public static void RegisterTypes(IUnityContainer container)
        {
            // Add your register logic here...
            var myAssemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.StartsWith("DataAccess")).ToArray();

            container.RegisterType(typeof(Startup));

            container.RegisterTypes(
                UnityHelpers.GetTypesWithCustomAttribute <LifecycleSingletonAttribute>(myAssemblies),
                WithMappings.FromMatchingInterface,
                WithName.Default,
                WithLifetime.ContainerControlled,
                null
                ).RegisterTypes(
                UnityHelpers.GetTypesWithCustomAttribute <LifecycleTransientAttribute>(myAssemblies),
                WithMappings.FromMatchingInterface,
                WithName.Default,
                WithLifetime.Transient);
        }
コード例 #3
0
        // This code configures Web API. The Startup class is specified as a type
        // parameter in the WebApp.Start method.
        public void Configuration(IAppBuilder appBuilder)
        {
            // Configure Web API for self-host.
            var config = new HttpConfiguration();

            // Add Unity DependencyResolver
            config.DependencyResolver = new UnityDependencyResolver(UnityHelpers.GetConfiguredContainer());

            // Add Unity filters provider
            RegisterFilterProviders(config);

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            appBuilder.UseWebApi(config);
        }
コード例 #4
0
        // This code configures Web API. The Startup class is specified as a type
        // parameter in the WebApp.Start method.
        public void Configuration(IAppBuilder appBuilder)
        {
            // Configure Web API for self-host.
            var config = new HttpConfiguration();

            //config.TransferMode = TransferMode.Streamed;
            // Add Unity DependencyResolver
            config.DependencyResolver = new UnityDependencyResolver(UnityHelpers.GetConfiguredContainer());

            // Add Unity filters provider
            RegisterFilterProviders(config);

            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);

            // Web API routes
            config.MapHttpAttributeRoutes();

            appBuilder.UseWebApi(config);
        }
コード例 #5
0
ファイル: Startup.cs プロジェクト: majed2010/ExamReservation2
        private static void RegisterFilterProviders(HttpConfiguration config)
        {
            // Add Unity filters provider
            var providers = config.Services.GetFilterProviders().ToList();

            config.Services.Add(typeof(System.Web.Http.Filters.IFilterProvider), new WebApiUnityActionFilterProvider(UnityHelpers.GetConfiguredContainer()));
            var defaultprovider = providers.First(p => p is ActionDescriptorFilterProvider);

            config.Services.Remove(typeof(System.Web.Http.Filters.IFilterProvider), defaultprovider);
        }