English 中文(简体)
我如何控制会员创造/生活时间?
原标题:How do I control MembershipProvider instance creation/lifetime?

我在我的网页上登记了一个习俗成员课程。 使用Cas 温莎的Inversion Of Control,我已经将我的习俗成员类别登记为转手人(因为后者也使用一种转手服务)。

这意味着,我要求每个网络要求重新审理会员提供人的情况。 目前,它只是每个申请领域创建一次,这样,当它试图获得它所依赖的服务时,这种服务案例才被重复使用,而不必再使用。

现在,我需要找到一种办法,突然控制我的习俗成员,但我不知道如何。 我期望在“NET”框架内的某个地方开展一次紧急事件,使我能够放弃案件的创造,并将案件转至紧急情况,但我可以找到任何东西。

因此,Im使用4.0。

<><>UPDATE: 在这里,我的一些法典使你能够看到我所做的事情:

Web.Config:

<membership defaultProvider="MyMembershipProvider" >
  <providers>
    <clear/>
    <add name="ApplicationMembershipProvider"
         type="MyNamespace.MyMembershipProvider, MyAssembly"/>
  </providers>
</membership>

<>成员<>

public class MyMembershipProvider : MembershipProvider
{
    private IMyService myService;

    public MyMembershipProvider() : base()
    {
        // We should use constructor injection here but since we cannot control
        // the construction of this class, we re forced to create the dependency
        // ourselves.
    }

    public override bool ValidateUser(string username, string password)
    {
        if (myService == null)
        {
            // This scope is only reached once within the browser session,
            // ASP.NET keeps the instance of MyMembershipProvider in memory
            // so the myService field keeps its value across web requests.
            // This results in Castle Windsor (which I have configured the service
            // locator to use) not being able to control the lifetime of
            // the MyService instance. So, the inability of Windsor to control
            // the lifetime of MembershipProvider instances, inhibits the lifetime
            // management of MyService instances as well.
            myService = ServiceLocator.Current.GetInstance<IMyService>();
        }

        return myService.ValidateUser(username, password);
    }
}
最佳回答

见http://bugsquash.blogspot.com/

简言之,这一解决办法涉及一个简单、可再利用的成员提供人,要求集装箱解决你的客户。 与使用“BuildUp”集装箱特征的其他解决办法不同的是,这种办法真正控制了瞬时状态,从而使构造注射(反过来又能够变换)和代理。

问题回答

对您的终身任期表示担忧。 简单地管理供应商内部的监保服务寿命。 • 为您的监文服务公司创造财产,每当其要求时,将新情况(或你希望管理终身)退回。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签