Yes it is possible. The following is a simple example of how you can achieve it:
class Program { public interface IQueryHandler{} private class QueryHandler : IQueryHandler { } private class CacheQueryHandler : IQueryHandler { } public interface IService { } private class Service : IService { private readonly IQueryHandler _queryHandler; private readonly IQueryHandler _cacheQueryHandler; public Service(IQueryHandler queryHandler, IQueryHandler cacheQueryHandler) { _queryHandler = queryHandler; _cacheQueryHandler = cacheQueryHandler; } public override string ToString() { return string.Format("_queryHandler is {0}; _cacheQueryHandler is {1}", _queryHandler, _cacheQueryHandler); } } static void Main(string[] args) { var builder = new ContainerBuilder();
Update:
Basically you need to:
1. Come up with a general agreement. The prefix "cache" of the ctor parameter name in your case.
2. Register your dependencies as usual.
3. Register your decorators so that they do not overwrite your original dependencies, and you can easily solve them based on your agreement. e.g. Key, Named, through Attribute, etc.
4. Register the actual implementation of the class using decorators
5. Register your interface describing the class using a lambda expression that has all the magic inside.
Note. I presented a simple and working example. It is up to you to make it beautiful, easy to use and fast, for example. make it as an extension, generic, cache reflection result, etc. In any case, it is not difficult.
Thanks.
source share