Let say that I have this service and two strategies for it:
public class SomeService<TEntity> : ISomeService<TEntity>
{
public SomeService(ICurrentDbContext context, IStrategy<TEntity>? delete = null)
: base(context, delete ?? new DefaultStrategy<TEntity>())
{}
}
public class DefaultStrategy<TEntity> : IStrategy<TEntity> {}
public class CustomStrategy<TEntity> : IStrategy<TEntity> {}
My current registration of service looks like this:
container.Register(typeof(ISomeService<>), typeof(SomeService<>), Reuse.Transient);
What I want to achieve here is to pass CustomStrategy on resolution attempt of ISomeService if generic type parameter T implements some interface, let say for example IFoo. Otherwise, keep it as a parameter with the default value null.
Ofc the first param should be automatically resolved in both cases as a registered dependency.
Don't have any idea for now how to do that, should I use Interceptors for it?
You may do it like this (but it is not clear from your question why you have two strategies
DefaultStrategy<TEntity>
andCustomStrategy<TEntity>
).