当前位置: 首页>>代码示例>>C#>>正文


C# IAppBuilder.UseAutofacWebApi方法代码示例

本文整理汇总了C#中IAppBuilder.UseAutofacWebApi方法的典型用法代码示例。如果您正苦于以下问题:C# IAppBuilder.UseAutofacWebApi方法的具体用法?C# IAppBuilder.UseAutofacWebApi怎么用?C# IAppBuilder.UseAutofacWebApi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IAppBuilder的用法示例。


在下文中一共展示了IAppBuilder.UseAutofacWebApi方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Configure

        public static void Configure(IAppBuilder app)
        {
            //Autofac configuration
            var builder = new ContainerBuilder();
            // Get your HttpConfiguration.
            var config = new HttpConfiguration();

            // Register your Web API controllers.
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterType<AccountController>().InstancePerRequest();
            builder.RegisterType<PhoneBookContext>().InstancePerRequest();

            //dependenses resolving
            builder.RegisterType<MainUserManager>().As<IMainUserManager>().InstancePerRequest();
            builder.Register(c => new UserStore<User>(c.Resolve<PhoneBookContext>())).AsImplementedInterfaces().InstancePerRequest();

            builder.RegisterType<ApplicationUserManager>().AsSelf();

            // Set the dependency resolver to be Autofac.
            var container = builder.Build();
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            app.UseAutofacWebApi(config);
            app.UseAutofacMiddleware(container);
            app.UseAutofacWebApi(config);
            app.UseWebApi(config);
        }
开发者ID:ramzzzay,项目名称:PhoneBook,代码行数:27,代码来源:AutofacConfig.cs

示例2: Configuration

        public void Configuration(IAppBuilder app)
        {
            // Setup db context for use in DI
            app.Use(async (context, next) =>
            {
                TestDbContext dbContext = _dbContextFactory(context);
                context.Set(DbContextKey, dbContext);

                await next();

                dbContext.Dispose();
            });

            var appContainerBuilder = new ContainerBuilder();
            appContainerBuilder.Register(ctx => HttpContext.Current.GetOwinContext()).As<IOwinContext>();
            appContainerBuilder.Register(c => c.Resolve<IOwinContext>().Get<TestDbContext>(DbContextKey)).As<TestDbContext>();
            appContainerBuilder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            var appContainer = appContainerBuilder.Build();
            app.UseAutofacMiddleware(appContainer);

            var httpConfig = GetWebApiConfiguration();
            httpConfig.DependencyResolver = new AutofacWebApiDependencyResolver(appContainer);
            app.UseWebApi(httpConfig);
            app.UseAutofacWebApi(httpConfig);
        }
开发者ID:Eclarian,项目名称:JSONAPI.NET,代码行数:25,代码来源:Startup.cs

示例3: ConfigureMobileApp

        /// <summary>
        /// Configures the webApi dependency injection to start the service.
        /// </summary>
        /// <param name="app">The Azure app service mobile app to configure.</param>
        public static void ConfigureMobileApp(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();
            config.Services.Add(typeof(IExceptionLogger), new ApplicationInsightsExceptionLogger());

            IContainer container = ConfigureWebApiDependencies();
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            config.MapHttpAttributeRoutes();

            new MobileAppConfiguration()
                .AddMobileAppHomeController()
                .MapApiControllers()
                .ApplyTo(config);

            app.UseAutofacMiddleware(container);
            app.UseAutofacWebApi(config);
            app.UseWebApi(config);

            // Configure Application Insights Telemetry.
            TelemetryConfiguration.Active.InstrumentationKey = SystemContext.Current.Environment.InstrumentationKey;

            var rootPath = HttpContext.Current.Server.MapPath("~");
            var serverPath = Path.Combine(rootPath, "bin");

            using (var scope = container.BeginLifetimeScope())
            {
                var repository = scope.Resolve<IRepository>();

                // Do database initialization synchronously
                repository.InitializeDatabaseIfNotExisting(serverPath).ConfigureAwait(false).GetAwaiter().GetResult();
            }
        }
开发者ID:Microsoft,项目名称:Appsample-Photosharing,代码行数:36,代码来源:Startup.MobileApp.cs

示例4: Configuration

        public void Configuration(IAppBuilder app)
        {
            var autoFacBuilder = new ContainerBuilder();
            HttpConfiguration config = new HttpConfiguration();

            ConfigureAutoFac(autoFacBuilder);
            autoFacBuilder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            autoFacBuilder.RegisterWebApiFilterProvider(config);
            autoFacBuilder.RegisterWebApiModelBinders(Assembly.GetExecutingAssembly());
            var container = autoFacBuilder.Build();

            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            app.UseAutofacMiddleware(container);
            app.UseAutofacWebApi(config);
            ConfigureAuth(app);
            WebApiConfig.Register(config);


            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
            app.UseWebApi(config);

            config.EnsureInitialized();

        }
开发者ID:nandithakw,项目名称:hasl,代码行数:25,代码来源:Startup.cs

示例5: Configuration

        public void Configuration(IAppBuilder app)
        {
            var config = new HttpConfiguration();
            ConfigureFilters(app, config);
            ConfigureWebApi(app, config);

            var container = ConfigureDI(app, config);

            app.UseAutofacWebApi(config);
            app.UseAutofacMiddleware(container);

            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions()
            {
                Provider = container.Resolve<IOAuthBearerAuthenticationProvider>()
            });

            app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp = true,
                TokenEndpointPath = new PathString("/api/auth/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(7),
                Provider = container.Resolve<IOAuthAuthorizationServerProvider>()
            });

            app.UseWebApi(config);
        }
开发者ID:o-panikarovskiy,项目名称:fms,代码行数:26,代码来源:Startup.cs

示例6: Configure

        public static void Configure(IAppBuilder app)
        {
            if (app == null)
                throw new ArgumentNullException("app");

            IContainer container = IocConfiguration.BuildContainer(actorSystemName: "Wakka");
            app.UseAutofacMiddleware(container);

            HttpConfiguration webApiConfiguration = new HttpConfiguration
            {
                // Only used when mapping attribute routes.
                DependencyResolver = new AutofacWebApiDependencyResolver(container)
            };
            app.UseAutofacWebApi(webApiConfiguration); // Share OWIN lifetime scope.

            webApiConfiguration.MapHttpAttributeRoutes();
            webApiConfiguration.EnsureInitialized();

            app.UseWebApi(webApiConfiguration);

            // Explicitly start the actor system when the OWIN app is started.
            ActorSystem actorSystem = container.ResolveNamed<ActorSystem>("Wakka");

            // Try to gracefully shut down the actor system when the host is shutting down.
            AppProperties appProperties = new AppProperties(app.Properties);
            appProperties.OnAppDisposing.Register(() =>
            {
                actorSystem.Shutdown();
                actorSystem.AwaitTermination(
                    timeout: TimeSpan.FromSeconds(5)
                );
            });
        }
开发者ID:tintoy,项目名称:Wakka,代码行数:33,代码来源:OwinConfiguration.cs

示例7: Configuration

        public void Configuration(IAppBuilder app)
        {
            // Loading a new configuration.
            var config = new HttpConfiguration();
            config.MapHttpAttributeRoutes();

            // Loading formatters.
            var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().First();
            jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            jsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));

            // Resolving Dependencies
            var builder = new ContainerBuilder();
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
            builder.RegisterModule(new DataLayerModule());

            var container = builder.Build();
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            // Configuring Mappings
            DataLayerMapping.AutoMapperStart();

            app.UseAutofacMiddleware(container);
            app.UseAutofacWebApi(config);
            app.UseWebApi(config);
        }
开发者ID:renelopez,项目名称:PIUManagementAPI,代码行数:26,代码来源:Startup.cs

示例8: ConfigureDependencies

        private void ConfigureDependencies(IAppBuilder app, 
            HttpConfiguration config)
        {
            // configure container
            ContainerBuilder builder = new ContainerBuilder();

            // bind all webapi controllers
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly())
                .InstancePerRequest();

            // register context
            builder.RegisterType<TemplateAppContext>()
                .AsSelf()
                .InstancePerRequest();

            // register services
            builder.RegisterType<ConfigurationService>()
                .As<IConfigurationService>()
                .InstancePerLifetimeScope();
            builder.RegisterType<UserService>()
                .As<IUserService>()
                .InstancePerRequest();

            // create container
            IContainer container = builder.Build();

            // bind app to autofac
            app.UseAutofacMiddleware(container);
            app.UseAutofacWebApi(config);
        }
开发者ID:nascentdigital,项目名称:web-template,代码行数:30,代码来源:Startup.DependencyInjection.cs

示例9: Register

        /// <summary>
        ///     Registers the configuration
        /// </summary>
        public static IContainer Register(IAppBuilder app, HttpConfiguration configuration, IServiceFacade serviceFacade = null)
        {
            Condition.Requires(configuration, "configuration").IsNotNull();

            var builder = new ContainerBuilder();

            builder.RegisterModule(new ServiceModule(serviceFacade));

            // controllers
            builder.RegisterApiControllers(typeof (ControllerBase).Assembly);

            // request
            builder.RegisterHttpRequestMessage(configuration);

            // authorization
            builder.RegisterType<AuthorizationServerProvider>().As<IOAuthAuthorizationServerProvider>().SingleInstance();

            // set resolver
            var container = builder.Build();

            // set the dependency resolver for Web API
            var resolver = new AutofacWebApiDependencyResolver(container);
            configuration.DependencyResolver = resolver;
            app.UseAutofacMiddleware(container);
            app.UseAutofacWebApi(configuration);

            ConfigureOAuth(app, container);

            app.UseWebApi(configuration);

            return container;
        }
开发者ID:RMcD,项目名称:AngularSkeleton.NET,代码行数:35,代码来源:ContainerConfig.cs

示例10: Register

        public static void Register(IAppBuilder app, HttpConfiguration config)
        {
            var aspNetIdentityAssembly = typeof(IMarkerAspNetIdentityInterface).Assembly;
            var cornhouseCoreAssembly = typeof (IMarkerCornhouseCoreInterface).Assembly;
            var executingAssembly = Assembly.GetExecutingAssembly();
            
            var builder = new ContainerBuilder();

            builder.Register(c => InitializeRavenDb.Initialize(aspNetIdentityAssembly)).As<IDocumentStore>().InstancePerLifetimeScope();
            builder.Register(c => c.Resolve<IDocumentStore>().OpenAsyncSession()).As<IAsyncDocumentSession>().InstancePerRequest();
            builder.Register(c => HttpContext.Current.User).InstancePerRequest();

            builder.RegisterType<ApplicationUserManager>().AsSelf().InstancePerRequest();
            builder.RegisterType<ApplicationRoleManager>().AsSelf().InstancePerRequest();
            builder.RegisterType<RavenUserStore>().AsSelf().InstancePerRequest();
            builder.RegisterType<RavenRoleStore>().AsSelf().InstancePerRequest();
            

            builder.Register(c => HttpContext.Current.GetOwinContext().Authentication).InstancePerRequest();
            builder.Register(c => app.GetDataProtectionProvider()).InstancePerRequest();

            builder.RegisterApiControllers(executingAssembly);
            builder.RegisterApiControllers(aspNetIdentityAssembly);

            builder.RegisterAssemblyTypes(executingAssembly).AsImplementedInterfaces().InstancePerRequest();
            builder.RegisterAssemblyTypes(aspNetIdentityAssembly).AsImplementedInterfaces().InstancePerRequest();
            builder.RegisterAssemblyTypes(cornhouseCoreAssembly).AsImplementedInterfaces().InstancePerRequest();
            
            
            var container = builder.Build();
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            app.UseAutofacMiddleware(container);
            app.UseAutofacWebApi(config);            
        }
开发者ID:jeremy-holt,项目名称:Cornhouse.Factory-Mutran,代码行数:35,代码来源:AutofacConfig.cs

示例11: Configuration

        public void Configuration(IAppBuilder app)
        {
            TI.trace("StartupServerAutofac", "Begin in memory server setup");
            Stopwatch sw = new Stopwatch();
            sw.Start();
            var configuration = new HttpConfiguration();
            //configuration.EnableSystemDiagnosticsTracing();
            //configuration.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //); 
            //add some temp route hacks
            configuration.Routes.MapHttpRoute(
                name: "Login1",
                routeTemplate: "Login/Login",
                defaults: new { controller = "Login", action = "LoginGet" });
             
            WebApiConfig.RegisterRoutes(configuration);
            WebApiConfig.RegisterIntegrationRoutes(configuration);
            DB_TestingHelper dbHelper = DefaultDbTestingHelper.GetDefaultDbTestingHelper();
            ContainerBuilder b = IOCHelper.InitializeServerWithAutofacContainer(dbHelper.Server_DistributrExmxConnection, dbHelper.MongoConnectionString, "win", dbHelper.MongoAuditingConnectionString);
            Assembly a = Assembly.GetAssembly(typeof(Distributr.WebApi.ApiControllers.CommandController));
            b.RegisterApiControllers(a);
            Autofac.IContainer c = b.Build();
            System.Web.Http.Dependencies.IDependencyResolver r = new AutofacWebApiDependencyResolver(c) ;
            configuration.DependencyResolver = r;
            app.UseAutofacMiddleware(c);
            app.UseAutofacWebApi(configuration);
            app.UseWebApi(configuration);
            sw.Stop();
            TI.trace("[StartupServerAutofac]",
                string.Format("Time taken to setup in memory server {0}", sw.ElapsedMilliseconds));

        }
开发者ID:asanyaga,项目名称:BuildTest,代码行数:35,代码来源:StartupServerAutofac.cs

示例12: Start

        protected virtual void Start(IAppBuilder app, IContainer container)
        {
            var config = CreateHttpConfiguration();

            ConfigureWebApi(config);

            if (Settings.ShowExceptionDetails)
            {
                app.UseErrorPage(new ErrorPageOptions
                {
                    ShowExceptionDetails = true,
                    ShowSourceCode = true
                });
            }
            
            app.UseAutofacMiddleware(container);
            app.UseAutofacWebApi(config);
            app.UseWebApi(config);
            RegisterSignalR(container, app);

            app.UseStageMarker(PipelineStage.MapHandler);

            RegisterServices(container, app, config);
            
            RegisterShutdown(app, container);

            StartIndexingIfConfigured(container);
        }
开发者ID:jjchiw,项目名称:NuGet.Lucene,代码行数:28,代码来源:Startup.cs

示例13: ConfigureAutofac

        public void ConfigureAutofac(IAppBuilder app)
        {
            var builder = new ContainerBuilder();

            // register the class that sets up bindings between interfaces and implementation
            builder.RegisterModule(new WebAutofacModule());

            // register configuration provider
            builder.RegisterType<ConfigurationProvider>().As<IConfigurationProvider>();

            // register Autofac w/ the MVC application
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            // Register the WebAPI controllers.
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            var container = builder.Build();

            // Setup Autofac dependency resolver for MVC
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            // Setup Autofac dependency resolver for WebAPI
            Startup.HttpConfiguration.DependencyResolver = new AutofacWebApiDependencyResolver(container);

            // 1.  Register the Autofac middleware 
            // 2.  Register Autofac Web API middleware,
            // 3.  Register the standard Web API middleware (this call is made in the Startup.WebApi.cs)
            app.UseAutofacMiddleware(container);
            app.UseAutofacWebApi(Startup.HttpConfiguration);
        }
开发者ID:smartpcr,项目名称:azure-iot-remote-monitoring,代码行数:30,代码来源:Startup.Autofac.cs

示例14: Configuration

        public void Configuration(IAppBuilder app)
        {
            var config = new HttpConfiguration();

            var container = ConfigureAutoFac.ConfigureMvc();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
            //Dit op Configure laten staan, dit wordt namelijk niet in web requests gebruikt
            // Remove the old formatter, add the new one.
            var formatter = new JsonMediaTypeFormatter();
            formatter.SerializerSettings = new JsonSerializerSettings
            {
                Formatting = Formatting.Indented,
                ContractResolver = new CamelCasePropertyNamesContractResolver(),
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            };

            config.Formatters.Remove(config.Formatters.JsonFormatter);
            config.Formatters.Add(formatter);
            config.Formatters.Remove(config.Formatters.XmlFormatter);
            WebApiConfig.Register(config);

            app.UseCors(CorsOptions.AllowAll);
            app.UseAutofacMiddleware(container);
            app.UseAutofacMvc();
            app.UseAutofacWebApi(config);
            app.UseWebApi(config);
            ConfigureAuth(app);
        }
开发者ID:SergeBekenkamp,项目名称:DungeonsAndDragons5eCharacterEditor,代码行数:30,代码来源:Startup.cs

示例15: Configuration

        public void Configuration(IAppBuilder app)
        {
            var config = new HttpConfiguration();

            // Web API routes
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional });

            // Remove XML formatter
            var json = config.Formatters.JsonFormatter;
            json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None;
            config.Formatters.Remove(config.Formatters.XmlFormatter);

            // NetIn and assign a dependency resolver for Web API to use.
            var dependencyResolver = new DependencyResolver();
            config.DependencyResolver = dependencyResolver;

            // Filter for loggering
            var logActionFilter = new Containerizer.Filters.LogActionFilter(DependencyResolver.logger);
            config.Filters.Add(logActionFilter);
            var exceptionLoggingFilter = new Containerizer.Filters.ExceptionLoggingFilter(DependencyResolver.logger);
            config.Filters.Add(exceptionLoggingFilter);

            // Make sure the Autofac lifetime scope is passed to Web API.
            app.UseAutofacWebApi(config);

            app.MapWebSocketPattern<ContainerProcessHandler>("/api/containers/(?<handle>.*)/run", dependencyResolver);

            app.UseWebApi(config);
        }
开发者ID:stefanschneider,项目名称:garden-windows,代码行数:30,代码来源:Startup.cs


注:本文中的IAppBuilder.UseAutofacWebApi方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。