开发者

How can I register generic class as IHttpModule

publ开发者_开发百科ic class NHibernateSessionPerRequest<T>:IHttpModule
{
    public void Dispose() { }

    public void Init(HttpApplication context)
    {
        context.BeginRequest += BeginRequest;
        context.EndRequest += EndRequest;
    }
}

How can it be registered in web.config?


IIS6 : In the system.web section of your web.config

<configuration>
  <system.web>
    <httpModules>
      <add name="MyModule" type="My.Namespace.NHibernateSessionPerRequest`1[[My.Namespace.MyType, My.Assembly]], My.Assembly"/>
    </httpModules>
  </system.web>
</configuration>

IIS7 : In the system.webserver section of your web.config :

<configuration>
  <system.webServer>
    <modules>
      <add name="MyModule" type="My.Namespace.NHibernateSessionPerRequest`1[[My.Namespace.MyType, My.Assembly]], My.Assembly"/>
    </modules>
  </system.webServer>
</configuration>

For both, replace "My.Namespace" with the namespace of the class, and "My.Assembly" with the assembly name.


The easiest solution is to create a concrete type that derives from this type, and then register that:

public class MyActualModule : NHibernateSessionPerRequest<SomeType> {
}

Then in web.config register MyActualModule.

Alternatively, you can use the CLR-compliant syntax for generic types, but it's so awful that I won't even mention it here. Even a simple type like yours will have a type name that's probably over 100 chars long.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜