WebActivatorEx—动态注册httpmodle
源代码: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的更多相关文章
- Mvc动态注册HttpModule详解
序言 注册Httpmodule可以让我们使用HttpApplication对象中的处理管道事件.目前大家所熟知的应该有2种方式来使用HttpApplication对象中的处理管道事件.第一种是通过Gl ...
- RPC原来就是Socket——RPC框架到dubbo的服务动态注册,服务路由,负载均衡演化
序:RPC就是使用socket告诉服务端我要调你的哪一个类的哪一个方法然后获得处理的结果.服务注册和路由就是借助第三方存储介质存储服务信息让服务消费者调用.然我们自己动手从0开始写一个rpc功能以及实 ...
- 你必须知道ASP.NET知识------关于动态注册httpmodule(对不起汤姆大叔)
一.关于动态注册的问题 很多人看过汤姆大叔的MVC之前的那点事儿系列(6):动态注册HttpModule ,其实汤姆大叔没有发现httpmodule动态注册的根本机制在哪里. 亦即:怎么动态注册?为什 ...
- Android开发4: Notification编程基础、Broadcast的使用及其静态注册、动态注册方式
前言 啦啦啦~(博主每次开篇都要卖个萌,大家是不是都厌倦了呢~) 本篇博文希望帮助大家掌握 Broadcast 编程基础,实现动态注册 Broadcast 和静态注册 Broadcast 的方式以及学 ...
- Android只能动态注册的广播Action
只能动态注册的广播(部分): android.intent.action.SCREEN_ON android.intent.action.SCREEN_OFF android.intent.actio ...
- Oracle监听的静态注册和动态注册
静态注册:通过解析listene.ora文件 动态注册:由PMON进程动态注册至监听中 在没有listener.ora配置文件的情况下,如果启动监听,则监听为动态注册.用图形化netca创建的监听,默 ...
- .net比较完美的动态注册com组件
.net中经常需要使用com组件,怎么样注册com组件呢? 一般想到的当然是直接通过系统cmd 调用regsvr32注册程序去注册,如下: regsvr32 name.dll 在.net中可以直接执行 ...
- 在Asp.net 4.0 中动态注册HttpModule
using System; using System.Web; using Microsoft.Web.Infrastructure; namespace MvcApplication1 { publ ...
- MVC之前的那点事儿系列(6):动态注册HttpModule
文章内容 通过前面的章节,我们知道HttpApplication在初始化的时候会初始化所有配置文件里注册的HttpModules,那么有一个疑问,能否初始化之前动态加载HttpModule,而不是只从 ...
随机推荐
- db2 查杀死锁进程
db2 查杀死锁进命令 db2 get snapshot for locks on (需要snapshot的访问权限) db2 list applications db2 "force ap ...
- How to add the ApplicationPoolIdentity to a SQL Server Login
The ApplicationPoolIdentity is a virtual account in Windows that is dynamically generated when the a ...
- 没有上司的舞会|codevs1380|luoguP1352|树形DP|Elena
没有上司的舞会 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description Ural大学有N个职员,编号为1~N.他们有从属关系 ...
- .NET Core开发日志——Edge.js
最近在项目中遇到这样的需求:要将旧有系统的一部分业务逻辑集成到新的自动化流程工具中.这套正在开发的自动化工具使用的是C#语言,而旧有系统的业务逻辑则是使用AngularJS在前端构建而成.所以最初的考 ...
- [No000013D].Net 项目代码风格参考
1. C#代码风格要求 1.1 注释 类型.属性.事件.方法.方法参数,根据需要添加注释. 如果类型.属性.事件.方法.方法参数的名称已经是自解释了,不需要加注释:否则需要添加注释. 当添加注释时,添 ...
- java获取文件的路径问题
java获取文件的路径问题 在java中读取读取文件,经常因为路径的问题找不到,此文用于记录如何定位文件的简单方法. 本基于springboot做的测试,主要是构建工程方便,所用的方法都是JDK中的方 ...
- tensorflow 的tf.where详解
最近在用到数据筛选,观看代码中有tf.where()的用法,不是很常用,也不是很好理解.在这里记录一下 tf.where( condition, x=None, y=None, name=None ) ...
- C# decimal指定精度
最近做一个项目.遇到了decimal 如何指定精度的问题 一般的指定参数 param = new SqlParameter(ParamName, DbType); 但decimal就不能只通过构 ...
- linux 模拟发http请求的例子
curl -X POST --header "Content-Type: application/json" --header "Accept: */*" &q ...
- cb && cb() 和 a || {}
cb && cb() 等同于 if(cb != undefined) { cb(); } a || {} var flag = false var a = flag || {} a / ...