Ejemplo n.º 1
0
        public static void Resolve(ContainerBuilder builder)
        {
            // Register your MVC controllers. (MvcApplication is the name of
            // the class in Global.asax.)
            builder.RegisterControllers(typeof(WebApiApplication).Assembly);

            // OPTIONAL: Register model binders that require DI.
            builder.RegisterModelBinders(typeof(WebApiApplication).Assembly);
            builder.RegisterModelBinderProvider();

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule <AutofacWebTypesModule>();

            // OPTIONAL: Enable property injection in view pages.
            builder.RegisterSource(new ViewRegistrationSource());

            // OPTIONAL: Enable property injection into action filters.
            builder.RegisterFilterProvider();

            // OPTIONAL: Enable action method parameter injection (RARE).
            //builder.InjectActionInvoker();

            ServiceDependencyRegister.Resolve(builder);

            // Set the dependency resolver to be Autofac.
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Ejemplo n.º 2
0
        public static void Resolve(ContainerBuilder builder)
        {
            //// Get your HttpConfiguration.
            //var config = GlobalConfiguration.Configuration;

            //// Register your Web API controllers.
            //builder.RegisterApiControllers(typeof(WebApiApplication).Assembly);
            ////builder.RegisterControllers(typeof(WebApiApplication).Assembly);


            //// OPTIONAL: Register the Autofac filter provider.
            //builder.RegisterWebApiFilterProvider(config);

            //// OPTIONAL: Register the Autofac model binder provider.
            //builder.RegisterWebApiModelBinderProvider();

            //ServiceDependencyRegister.Resolve(builder);
            //// Set the dependency resolver to be Autofac.
            //var container = builder.Build();
            //DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            //config.DependencyResolver = new AutofacWebApiDependencyResolver(container);



            // Get your HttpConfiguration.
            var config = GlobalConfiguration.Configuration;

            // Register your Web API controllers.
            builder.RegisterApiControllers(typeof(WebApiApplication).Assembly);

            // OPTIONAL: Register the Autofac filter provider.
            builder.RegisterWebApiFilterProvider(config);

            // OPTIONAL: Register the Autofac model binder provider.
            builder.RegisterWebApiModelBinderProvider();

            ServiceDependencyRegister.Resolve(builder);
            // Set the dependency resolver to be Autofac.
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
Ejemplo n.º 3
0
        ////   public static string assemblyIncludingPattern;

        /// <summary>
        /// Resolves the specified builder.
        /// </summary>
        /// <param name="builder">The builder.</param>
        public static void Resolve(ContainerBuilder builder)
        {
            if (HttpContext.Current != null)
            {
                builder.Register(c =>
                                 new HttpContextWrapper(HttpContext.Current) as HttpContextBase)
                .As <HttpContextBase>()
                .InstancePerDependency();
            }

            builder.Register(c => c.Resolve <HttpContextBase>().Request)
            .As <HttpRequestBase>()
            .InstancePerDependency();
            builder.Register(c => c.Resolve <HttpContextBase>().Response)
            .As <HttpResponseBase>()
            .InstancePerDependency();
            builder.Register(c => c.Resolve <HttpContextBase>().Server)
            .As <HttpServerUtilityBase>()
            .InstancePerDependency();
            builder.Register(c => c.Resolve <HttpContextBase>().Session)
            .As <HttpSessionStateBase>()
            .InstancePerDependency();

            ////builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()).Where(t => !t.IsAbstract && typeof(ApiController).IsAssignableFrom(t))
            ////    .InstancePerMatchingLifetimeScope();

            builder.RegisterControllers(typeof(GDS.API.WebApiApplication).Assembly);
            builder.RegisterApiControllers(typeof(GDS.API.WebApiApplication).Assembly);
            ServiceDependencyRegister.Resolve(builder);

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            //// Create the depenedency resolver.
            var resolver = new AutofacWebApiDependencyResolver(container);

            //// Configure Web API with the dependency resolver.
            GlobalConfiguration.Configuration.DependencyResolver = resolver;
        }