6

I'm using OpenRasta 2.0.3214.437 in an ASP.NET 4 web application. I'm registering a custom dependency in the internal container using:

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

This works perfectly for the first request; the second request throws an OpenRasta.DI.DependencyResolutionException after logging the message:

Ignoring constructor, following dependencies didn't have a registration: IRepository

DependencyLifetime.Singleton and DependencyLifetime.Transient work fine, just the PerRequest seems to have the issue. I'm running in Cassini. Am I doing something wrong?

Sam
  • 4,694
  • 2
  • 36
  • 47
  • Can you post an email on the mailing list with some test code so we can investigate the issue? – SerialSeb Mar 02 '11 at 10:53
  • Was this ever fixed, I'm seeing the same thing? – Neil Mosafi Sep 05 '11 at 09:20
  • Not to my knowledge. Registering the dependency in a pipeline contributor was my workaround. Also, are you using the right version of the code - I believe it's openrasta-core on github (not openrasta-stable). – Sam Sep 05 '11 at 13:50
  • Registering the dependency in a pipeline contributor? Can you explain more? Thanks – Neil Mosafi Sep 07 '11 at 19:54
  • 1
    Implement IPipelineContributor on a class, take a dependency on IDependencyResolver, then call resolver.AddDependencyInstance() at the start of each request. Register the pipeline contributor in your IConfigurationSource using ResourceSpace.Uses.PipelineContributor(). See https://github.com/openrasta/openrasta-stable/wiki/Implementing-a-PipelineContributor for more details on how to build a pipeline contributor. – Sam Sep 09 '11 at 02:21
  • @Sam if you add this as an answer to the question (as a workaround) I'll happy vote you up - this has gotten me out of a sticky situation today – Adam Ralph Oct 06 '11 at 14:29

2 Answers2

5

Workaround to this issue:

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

}

Then register the contributor in your IConfigurationSource:

ResourceSpace.Uses.PipelineContributor<RepositoryPipelineContributor>();
Sam
  • 4,694
  • 2
  • 36
  • 47
  • +1 Thanks Sam, I had the same issue using the default internal dependency manager (with InMemoryHost, not ASP) and this workaround works for me, too. – Evgeniy Berezovsky Nov 14 '11 at 03:53
0

Fixed in the 2.2 release, coming to a nuget soon.

SerialSeb
  • 6,701
  • 24
  • 28