Skip to content

UsingRegistrationStrategy -> RegistrationStrategy.Skip - Ability to skip if the implementation exists #167

Description

@DavidRooney

I am looking to implement a TryAddTransient solution but for scanning multiple interfaces. Currently my code will either add duplicates or I have a workaround which replaces the existing ones. What I really want is for the code to identify that the interfaces AND the implementations already exist so do nothing.

I'm a BDD kind of dev so here's the scenario:

Given I want to implement a strategy pattern with many classes implementing the same interface
When I hit the Scan code more than once
Then it will not add duplicates or replace existing services in the container

Current behaviour:
The skip functionality will perform a TryAdd which only appears to check the service. So when Scanning it will only add one implementation of that service rather than all the strategies.

Work around:
Use .UsingRegistrationStrategy(RegistrationStrategy.Replace(ReplacementBehavior.ImplementationType)).
But this will remove and replace those implementations with isn't specifically what I need

The code I wish I had:
.UsingRegistrationStrategy(RegistrationStrategy.Skip(SkipBehavior.ImplementationType)).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions