OpenRasta DI PerRequest Lifetime Issue

I am using OpenRasta 2.0.3214.437 in an ASP.NET 4 web application. I am registering a user dependency in an internal container using:

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

This works fine for the first request; the second request throws an OpenRasta.DI.DependencyResolutionException exception after registering the message:

Ignoring the constructor, depending on the dependencies, was not registered: IRepository

DependencyLifetime.Singleton and DependencyLifetime.Transient work fine, it seems to be a problem with PerRequest. I am running to Cassini. Am I doing something wrong?

+6
openrasta
source share
2 answers

Workaround to this issue:

IPipelineContributor implementation:

 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; } } 

Then register the contributor in the IConfigurationSource file:

 ResourceSpace.Uses.PipelineContributor<RepositoryPipelineContributor>(); 
+5
source share

Fixed in release 2.2, coming to nuget soon.

0
source share

All Articles