http://git.oschina.net/shiningrise/AutofacOwinDemo

using Microsoft.Owin;
using Owin;
using System.Web.Mvc; using Autofac;
using Autofac.Integration.Owin;
using Autofac.Integration.Mvc;
using Autofac.Integration.WebApi;
using System.Web.Http;
using System.Reflection;
using System.Web.Routing; [assembly: OwinStartupAttribute(typeof(AutofacOwinDemo.Startup))]
namespace AutofacOwinDemo
{
public partial class Startup
{
public void Configuration(IAppBuilder app)
{
//app.Run(context =>
//{
// context.Response.ContentType = "text/plain";
// return context.Response.WriteAsync("Hello World!");
//}); ConfigureAuth(app); var builder = new ContainerBuilder();
builder.RegisterType<Test1>().As<ITest>();
builder.RegisterType<Test2>();
builder.RegisterControllers(typeof(MvcApplication).Assembly); var config = new HttpConfiguration();
WebApiConfig.Register(config); builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterWebApiFilterProvider(config); var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
config.DependencyResolver = new AutofacWebApiDependencyResolver(container); app.UseAutofacMiddleware(container);
app.UseAutofacMvc(); app.UseAutofacWebApi(config);
app.UseWebApi(config); }
}
}

webform属性注入

pagebase方式

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; using Owin;
using Autofac;
using Autofac.Integration.Owin;
using System.Web; namespace AutofacOwinDemo
{
public partial class WebForm1 : System.Web.UI.Page
{
public ITest Test { get; set; } protected void Page_PreInit(object sender, EventArgs e)
{
var owin = this.Context.Request.GetOwinContext() ;
var scop = owin.GetAutofacLifetimeScope();
scop.InjectProperties(this);
} protected void Page_Load(object sender, EventArgs e)
{ }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using System.Web.Security;
using System.Web.SessionState; namespace AutofacOwinDemo
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas(); //GlobalConfiguration.Configure(WebApiConfig.Register); //这里要删除,让owin完全管理webapi FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
}

autofac + owin + webform + mvc + webapi集成demo的更多相关文章

  1. .net MVC, webAPI,webForm集成steeltoe+springcloud实现调用服务中心服务的总结

    开始之前,如果没接触过Autofac的,可以移步到Autofac官方示例学习一下怎么使用:https://github.com/autofac/Examples .net 下集成steeltoe进行微 ...

  2. Visual Studio 2015 Owin+MVC+WebAPI+ODataV4+EntityFrawork+Identity+Oauth2.0+AngularJS 1.x 学习笔记

    2016年,.net 会有很多大更新 ASP.NET 5 在此之前我都是用着古老的.net做开发的 (WebForm + IIS) 为了接下来应对 .net 的新功能,我特地去学习了一下基本的 MVC ...

  3. 基于OWIN ASP.NET WebAPI 使用OAUTH2授权服务的几点优化

    前面在ASP.NET WEBAPI中集成了Client Credentials Grant与Resource Owner Password Credentials Grant两种OAUTH2模式,今天 ...

  4. ASP.NET MVC WebApi 返回数据类型序列化控制(json,xml) 用javascript在客户端删除某一个cookie键值对 input点击链接另一个页面,各种操作。 C# 往线程里传参数的方法总结 TCP/IP 协议 用C#+Selenium+ChromeDriver 生成我的咕咚跑步路线地图 (转)值得学习百度开源70+项目

    ASP.NET MVC WebApi 返回数据类型序列化控制(json,xml)   我们都知道在使用WebApi的时候Controller会自动将Action的返回值自动进行各种序列化处理(序列化为 ...

  5. Taurus.MVC WebAPI 入门开发教程1:框架下载环境配置与运行(含系列目录)。

    前言: Taurus.MVC 微服务版本已经发布了:Taurus.MVC V3.0.3 微服务开源框架发布:让.NET 架构在大并发的演进过程更简单. 以前都是框架发布时写点相关功能点的文章,没有形成 ...

  6. 如何在 ASP.NET MVC 中集成 AngularJS(3)

    今天来为大家介绍如何在 ASP.NET MVC 中集成 AngularJS 的最后一部分内容. 调试路由表 - HTML 缓存清除 就在我以为示例应用程序完成之后,我意识到,我必须提供两个版本的路由表 ...

  7. Spring4 MVC Hibernate4集成 Annotation

    Spring4 MVC Hibernate4集成 Annotation 一.本文所用环境 二.工程目录 三.Maven添加依赖 四.新建数据库表 五.配置文件 六.Model层 七.DAO层 八.Se ...

  8. Spring4 MVC Hibernate4集成

      Spring4 MVC Hibernate4集成 一.    本文所用环境 Spring4.0.3.RELEASE Hibernate4.3.5.Final Mysql 二.    工程目录 三. ...

  9. .net和java和谐相处之安卓客户端+.net asp.net mvc webapi 2

    作为没有花很多时间转java,把java当C#用的我,在做服务器端程序的时候,自然不想考虑java web,java需要学的框架太多了,看了一下Java Servlet,始终没有编码的冲动.经过几天的 ...

随机推荐

  1. js-新窗口打开页面

    window.open(basePath+"/web/homeIndex?code="+code); 1.超链接<a href="http://www.xxx.ne ...

  2. Web性能测试基本指标

    Web性能测试基本指标 Web性能测试的部分概况一般来说,一个Web请求的处理包括以下步骤: (1)客户发送请求 (2)web server接受到请求,进行处理: (3)web server向DB获取 ...

  3. 【BZOJ-1324】Exca王者之剑 最小割

    1324: Exca王者之剑 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 483  Solved: 248[Submit][Status][Disc ...

  4. CMSEASY /lib/tool/front_class.php、/lib/default/user_act.php arbitrary user password reset vulnerability

    catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 攻击者通过构造特殊的HTTP包,可以直接重置任意用户(包括管理员)的密码 ...

  5. C#的imagebutton

    常常要用到好看一点的button去做,C#本身不提供imagebutton这个控件. 可以用如下方法: 用imagebox添加image图片.对此image进行事件的处理. 有时候所添加的image过 ...

  6. Java学习路线图

    参考<疯狂Java实战演义>制作,觉得可以做一参考(放大网页看)

  7. lbs(查看附近的人),看看社交软件如何实现查看附近的人

    最近在做一款移动端棋牌游戏,为了进一步提高用户体验.拉近玩家的距离,我们决定在游戏中加入好友功能,而对于体验好友功能的玩家来说,要是玩牌的时候可以看看附近都有谁在玩牌,跟他们交流交流玩牌心得什么的无疑 ...

  8. 捉襟见肘之自定义自拍相机AVFoundation

    因为上篇的问题的,我搜索到解决方法: http://stackoverflow.com/questions/5427656/ios-uiimagepickercontroller-result-ima ...

  9. Python 培训之正则表达式

    re 模块 re.math 从头匹配 re.search 结构: re.math(r'^c',a)   不符合返回None 原字符: . 任意字符 [ ] 或者 [A-Z,a-z,b] \d 数字 \ ...

  10. ubuntu 远程开机

    启动者(电脑A)  ----------->  被远程开启的电脑(电脑B) 一.被远程开启的电脑(电脑B):1. 重新开机,并进到BIOS设定2. 把Wake On Land / Wake On ...