dadhi / DryIoc

DryIoc is fast, small, full-featured IoC Container for .NET
MIT License
982 stars 122 forks source link

Feature Request: add global .WithDefaultServiceTypeCondition(Func<Type, bool> condition) method #640

Open ChaseFlorell opened 3 months ago

ChaseFlorell commented 3 months ago

Given the global Rules support within DryIoc, I would like to see an option to add a default serviceTypeCondition for all of my RegisterMany calls.

var container = new Container(Rules.Default
                                   .WithDefaultServiceTypeCondition(type => type.IsInterface))

The default behavior can still be ImTools Fun.Always when this method isn't overridden, but this would give us the ability to apply the same configuration across the entire application without the explicit need to call it on every registration.

dadhi commented 2 months ago

@ChaseFlorell Thanks for suggestion.

I think we need more RegisterMany targeted thingy, e.g. WithRegisterManyRules(serviceTypeConditon: t => t.IsInterface). So we keep the door open to extend it later.