6

ASP.NET 4 Web アプリケーションで OpenRasta 2.0.3214.437 を使用しています。以下を使用して、内部コンテナーにカスタム依存関係を登録しています。

ResourceSpace.Uses.CustomDependency<IRepository, Repository>(DependencyLifetime.PerRequest);

これは、最初のリクエストに対して完全に機能します。2 番目のリクエストは、メッセージを記録した後に OpenRasta.DI.DependencyResolutionException をスローします。

コンストラクターを無視して、次の依存関係に登録がありませんでした: IRepository

DependencyLifetime.Singleton と DependencyLifetime.Transient は正常に動作しますが、PerRequest だけに問題があるようです。私はカッシーニで走っています。私は何か間違ったことをしていますか?

4

2 に答える 2

5

この問題の回避策:

IPipelineContributor を実装します。

public class RepositoryPipelineContributor : IPipelineContributor
{
    private readonly IDependencyResolver resolver;

    public RepositoryPipelineContributor(IDependencyResolver resolver)
    {
        this.resolver = resolver;
    }

    public void Initialize(IPipeline pipelineRunner)
    {
        pipelineRunner.Notify(CreateRepository)
            .Before<KnownStages.IOperationExecution>();
    }

    private PipelineContinuation CreateRepository(ICommunicationContext arg)
    {
        resolver.AddDependencyInstance<IRepository>(new Repository(), DependencyLifetime.PerRequest);
        return PipelineContinuation.Continue;
    }

}

次に、コントリビューターを IConfigurationSource に登録します。

ResourceSpace.Uses.PipelineContributor<RepositoryPipelineContributor>();
于 2011-10-07T05:37:36.483 に答える
0

2.2 リリースで修正され、まもなく nuget になります。

于 2013-10-31T13:41:42.583 に答える