Skip to content

Add Container.Collection.RegisterConditional #1012

@dotnetjunkie

Description

@dotnetjunkie

Allow collections to be registered conditional, similar to what Container.RegisterConditional does for non-collection registrations.

e.g.:

container.Collection.RegisterConditional(
    serviceType: typeof(ILogger),
    serviceTypes: new[] { typeof(SqlLogger), typeof(FileLogger) },
    c => c.Consumer.Target.Name.StartsWith("realLoggers"));

container.Collection.RegisterConditional(
    serviceType: typeof(ILogger),
    serviceTypes: new[] { typeof(ConsoleLogger), typeof(NullLogger) },
    c => !c.Handled);

The difficulty in this feature is the following:

  • It should work for both ambient and flowing scope scenarios
  • It should work for all supported collection types

Related to #1009 and #1010.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions