源代码:https://github.com/davidebbo/WebActivator/tree/master/WebActivator

unity使用演示

WebActivator类库提供了3种功能,允许分别在Application_Start初始化之前,之后以及ShutDown的时候,分别执行指定的代码,并且允许多次指定。示例如下:

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(A.InitClass1), "PreStart")]
[assembly: WebActivatorEx.PostApplicationStartMethod(typeof(A.PostClass1), "PostStart")]
[assembly: WebActivatorEx.ApplicationShutdownMethod(typeof(A.ShutDownClass1), "ShutDown")]

项目演示

using System.Linq;
using System.Web.Mvc;
using Microsoft.Practices.Unity.Mvc; [assembly: WebActivatorEx.PreApplicationStartMethod(typeof(TestPrj.Common.PreUnityActivator), "Start")] namespace TestPrj.Common
{
public static class PreUnityActivator
{
/// <summary>Integrates Unity when the application starts.</summary>
public static void Start()
{
var container = UnityConfig.GetConfiguredContainer(); FilterProviders.Providers.Remove(FilterProviders.Providers.OfType<FilterAttributeFilterProvider>().First());
FilterProviders.Providers.Add(new UnityFilterAttributeFilterProvider(container)); DependencyResolver.SetResolver(new UnityDependencyResolver(container)); // if you want to use PerRequestLifetimeManager
// Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(UnityPerRequestHttpModule));
}
}
}
using System;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration; using TestPrj.DAL;
using TestPrj.Modules; namespace TestPrj.Web
{
/// <summary>
/// Main container.
/// </summary>
public class UnityConfig
{
private static Lazy<IUnityContainer> container = new Lazy<IUnityContainer>(() =>
{
var container = new UnityContainer();
RegisterTypes(container);
return container;
}); public static IUnityContainer GetConfiguredContainer()
{
return container.Value;
} public static void RegisterTypes(IUnityContainer container)
{
// NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements.
// container.LoadConfiguration(); // Register your types here
container.RegisterType<IPreUnitOfWork, ETravelEntities>(new PerResolveLifetimeManager()); // Register services.
container.RegisterType<IConfigService, ConfigService>();
}
}
}

WebActivatorEx—动态注册httpmodle的更多相关文章

  1. Mvc动态注册HttpModule详解

    序言 注册Httpmodule可以让我们使用HttpApplication对象中的处理管道事件.目前大家所熟知的应该有2种方式来使用HttpApplication对象中的处理管道事件.第一种是通过Gl ...

  2. RPC原来就是Socket——RPC框架到dubbo的服务动态注册,服务路由,负载均衡演化

    序:RPC就是使用socket告诉服务端我要调你的哪一个类的哪一个方法然后获得处理的结果.服务注册和路由就是借助第三方存储介质存储服务信息让服务消费者调用.然我们自己动手从0开始写一个rpc功能以及实 ...

  3. 你必须知道ASP.NET知识------关于动态注册httpmodule(对不起汤姆大叔)

    一.关于动态注册的问题 很多人看过汤姆大叔的MVC之前的那点事儿系列(6):动态注册HttpModule ,其实汤姆大叔没有发现httpmodule动态注册的根本机制在哪里. 亦即:怎么动态注册?为什 ...

  4. Android开发4: Notification编程基础、Broadcast的使用及其静态注册、动态注册方式

    前言 啦啦啦~(博主每次开篇都要卖个萌,大家是不是都厌倦了呢~) 本篇博文希望帮助大家掌握 Broadcast 编程基础,实现动态注册 Broadcast 和静态注册 Broadcast 的方式以及学 ...

  5. Android只能动态注册的广播Action

    只能动态注册的广播(部分): android.intent.action.SCREEN_ON android.intent.action.SCREEN_OFF android.intent.actio ...

  6. Oracle监听的静态注册和动态注册

    静态注册:通过解析listene.ora文件 动态注册:由PMON进程动态注册至监听中 在没有listener.ora配置文件的情况下,如果启动监听,则监听为动态注册.用图形化netca创建的监听,默 ...

  7. .net比较完美的动态注册com组件

    .net中经常需要使用com组件,怎么样注册com组件呢? 一般想到的当然是直接通过系统cmd 调用regsvr32注册程序去注册,如下: regsvr32 name.dll 在.net中可以直接执行 ...

  8. 在Asp.net 4.0 中动态注册HttpModule

    using System; using System.Web; using Microsoft.Web.Infrastructure; namespace MvcApplication1 { publ ...

  9. MVC之前的那点事儿系列(6):动态注册HttpModule

    文章内容 通过前面的章节,我们知道HttpApplication在初始化的时候会初始化所有配置文件里注册的HttpModules,那么有一个疑问,能否初始化之前动态加载HttpModule,而不是只从 ...

随机推荐

  1. hive优化之开启压缩功能

    1.开启hive作业mapreduce任务中间压缩功能: 对于数据进行压缩可以减少job中map和reduce task间的数据传输量.对于中间数据压缩,选择一个低cpu开销编/解码器要不选择一个压缩 ...

  2. win10 SVN不能显示图标

    参考的解决办法有很多(http://blog.csdn.net/lishehe/article/details/8257545),大多数是操作一下注册表. 我就按照他们的办法,svn的注册表顺序根本上 ...

  3. JavaScript面向对象之闭包的理解

    首先了解一下什么是闭包,闭包是一个函数,通常被称为闭包函数或者绑定函数,该函数运行在一个特殊的环境里,该环境定义了一些本地变量,当该函数被调用时,仍可以使用这些本地变量. 当一个函数在不位于它所处的环 ...

  4. 【编译原理】c++实现自下而上语法分析及中间代码(四元式)生成

    写在前面:本博客为本人原创,严禁任何形式的转载!本博客只允许放在博客园(.cnblogs.com),如果您在其他网站看到这篇博文,请通过下面这个唯一的合法链接转到原文! 本博客全网唯一合法URL:ht ...

  5. 2016年蓝桥杯省赛A组c++第4题(算法填空)

    /* 排序在各种场合经常被用到. 快速排序是十分常用的高效率的算法. 其思想是:先选一个“标尺”, 用它把整个队列过一遍筛子, 以保证:其左边的元素都不大于它,其右边的元素都不小于它. 这样,排序问题 ...

  6. json序列化以及反序列化存在多个对象时候的处理

    存在多个对象的时候,只需要将反序列化存在的对象,遍历出来即可. using System;using System.Collections.Generic;using System.Linq;usin ...

  7. wpf之WrapPanel与StackPanel

    WrapPanel: WrapPanel布局面板将各个控件从左至右按照行或列的顺序罗列,当长度或高度不够是就会自动调整进行换行.他有三个属性 Orientation——根据内容自动换行,ItemHei ...

  8. 中文乱码与字体库windows

    设置中文后,查看图形有乱码,文字变成了方块 Win+R打开运行,输入fonts,回车进入Windows字体目录,找到微软雅黑-常规字体,复制出来将文件名修改为msyh.ttf,注意后缀ttf. 将ms ...

  9. 使用c#反射实现接口可视化调试页面

    直接上代码,引用CommTools.dll.包括aspx显示页面和aspx.cs获取反射数据源代码 using System; using System.Collections.Generic; us ...

  10. [daily] 使用左右对比查看diff 格式的文件

    如题: Given your references to Vim in the question, I'm not sure if this is the answer you want :) but ...