Closed eValker closed 1 year ago
Ok, I think I figured this out.
container.RegisterDecorator<IAnimalRepository, CachedAnimalRepository>(c => c.AsServiceAlso<IDataRepository>().When(t => t.Type.IsAssignableTo(typeof(IAnimalRepository))));
container.RegisterDecorator<ICarRepository, CachedCarRepository>(c => c.AsServiceAlso<IDataRepository>().When(t => t.Type.IsAssignableTo(typeof(ICarRepository))));
container.RegisterDecorator<IPhoneRepository, CachedPhoneRepository>(c => c.AsServiceAlso<IDataRepository>().When(t => t.Type.IsAssignableTo(typeof(IPhoneRepository))));
Not sure if this is the best approach, but it is working :)
Hi @eValker, thank you for reporting this. I see you found a workaround but I recognised this as a bug. In 5.12.0-preview-821
it's now possible to register your decorators like:
container.RegisterDecorator<CachedAnimalRepository>(c => c.AsServiceAlso<IDataRepository>());
container.RegisterDecorator<CachedCarRepository>(c => c.AsServiceAlso<IDataRepository>());
container.RegisterDecorator<CachedPhoneRepository>(c => c.AsServiceAlso<IDataRepository>());
or:
container.RegisterDecorator<CachedAnimalRepository>(c => c.AsImplementedTypes());
container.RegisterDecorator<CachedCarRepository>(c => c.AsImplementedTypes());
container.RegisterDecorator<CachedPhoneRepository>(c => c.AsImplementedTypes());
The container will now treat your resolution request correctly. Could you please re-check your setup that it works now as expected? Thanks
Hello,
While working on a project I found weird resolver's behaviour. I ma not sure whether I am doing something wrong or if it is just a bug in the library :)
Here is a code sample to reproduce the issue:
Expected value
Inside CollectionOfServices constructor, I'm expecting to recieve an array of 3 different data repositories (for animals, cars and phones) wrapped in cached implementations and also HouseRepositry, e.g.
Actual value
CollectionOfServices constructor recieves an array of 4 CachedPhoneRepository instances.
I am not sure how can I change the configuration to achive what I need. I little help would be appreciated :)