Search code examples
dryioc

DryIoc, How to register transcient reuse (aka null) when default is set otherwise?


With dryIoc I have registered my container as such:

        var container = new Container(rules => rules
            .WithoutThrowOnRegisteringDisposableTransient()
            .WithDefaultReuseInsteadOfTransient(Reuse.Singleton)
        );

But then, I have to register transcient element, and since Reuse.Transcient == null, it gets replaced by the default I set (thus Reuse.Singleton). How can I overcome this?

        container.Register(Made.Of(() => new CandidateController(
            Arg.Of<IList<string>>("countryIsos")
        )),
            Reuse.Transient
        );

Solution

  • You cannot directly overcome this at the moment. I am recognizing that as a problem and will open corresponding issue.

    Until resolved you may use other reuse instead of Transient as workaround. Based on your situation closest to try would be Reuse.InResolutionScope. If you resolving the controller via Resolve method (or infrastructure does this for you), it will behave as Transient.

    Update: Here is the issue.