Ejemplo n.º 1
0
        public static void Register(HttpConfiguration config)
        {
            // Set unity container.
            var container = UnityContainerBuilder.getContainer();
            var resolver  = new UnityResolver(container);

            config.DependencyResolver = resolver;

            // Attribute routing.
            config.MapHttpAttributeRoutes();

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

            // Set message handlers.
            object authenticationHandler = container.Resolve(typeof(AuthenticationHandler), null);

            config.MessageHandlers.Add(authenticationHandler as AuthenticationHandler);

            // Set Filters.
            object exceptionFilter = container.Resolve(typeof(ExceptionFilter), null);

            config.Filters.Add(exceptionFilter as ExceptionFilter);
        }
Ejemplo n.º 2
0
        public TestsUnityContainer()
        {
            UnityContainer = new UnityContainer();
            var config = GetTestConfig();

            UnityContainer.RegisterInstance(typeof(TestConfig), config);
            ReflactionHelper = new ReflactionHelper(config.AssembliesPrefixes);
            UnityContainer.RegisterInstance(ReflactionHelper);
            var unityContainerBuilder = new UnityContainerBuilder(UnityContainer, ReflactionHelper);

            unityContainerBuilder.ConfigureContainer();
        }
Ejemplo n.º 3
0
        public static void Register(HttpConfiguration config)
        {
            // Unity
            UnityContainer      container = UnityContainerBuilder.Build();
            IDependencyResolver resolver  = new UnityResolver(container);

            config.DependencyResolver = resolver;

            // CORS
            EnableCorsAttribute corsAttr = new EnableCorsAttribute(ConfigurationManager.AppSettings["CORS_ALLOWED_ORIGINS"], "*", "*");

            config.EnableCors(corsAttr);

            // Web API routes
            config.MapHttpAttributeRoutes();

            // Global filters
            config.Filters.Add((ApiExceptionFilterAttribute)resolver.GetService(typeof(ApiExceptionFilterAttribute)));
            config.Filters.Add((AuthenticationFilter)resolver.GetService(typeof(AuthenticationFilter)));
            config.Filters.Add((AuthenticationRequiredAttribute)resolver.GetService(typeof(AuthenticationRequiredAttribute)));
        }
 public void SetUp()
 {
     Target = new UnityContainerBuilder();
 }