Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add InjectionConsumerInfo.Lifestyle property #714

dotnetjunkie opened this issue May 16, 2019 · 0 comments


None yet
1 participant
Copy link

commented May 16, 2019

Both the IDependencyInjectionBehavior abstraction and the RegisterConditional method make use of the InjectionConsumerInfo class:

  • IDependencyInjectionBehavior's Verify and GetInstanceProducer methods get supplied with an InjectionConsumerInfo instance.
  • RegisterConditional gets supplied with a Predicate<PredicateContext>. PredicateContext is supplied to the delegate by Simple Injector and contains a Consumer property of type InjectionConsumerInfo.

For registration and integration purposes, it is useful to include the lifestyle of the consuming component to the InjectionConsumerInfo.

This allows integration scenarios, like the following:

    Lifestyle.Singleton.CreateRegistration(() => provider, container),
    c => !c.Handled && c.Consumer?.Lifestyle == Lifestyle.Singleton);

        () => container.GetInstance<IServiceScope>().ServiceProvider,
    c => !c.Handled && c.Consumer?.Lifestyle != Lifestyle.Singleton);

In the code snippet, two separate IServiceProvider instances are registered. One for Singleton consumers, and another for Transient and Scoped components. This allows application components to be injected with either the root or scoped service provider, based on their lifestyle.

@dotnetjunkie dotnetjunkie added this to the Backlog milestone May 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.