I am new to Autofac and DI in general but I find it very powerful and look forward to integrating Autofac into some existing applications.
I have a WCF endpoint which handles multiple requests concurrently and I have used the Autofac.Wcf to inject a LogManager into the constructor of my handling class which works great. Also injected into that constructor is an IIndex of interfaces that can potentially handle that request depending on some information in the body of the request.
When the handling (c lass that implements the service contract interface) code is constructed I create a logger from the injected LogManager. This logger has data specific to this request, correlationId, etc. In the action operation code I use the injected IIndex to get the correct processor which works fine.
The problem is I need to inject the logger that was created in the handler constructor so I have all the ident info for that request. Since I don't register loggers into autofac, only the logmanager is registered, I don't see an elegant way to use autofac to automatically inject my logger instance. I know I can manually set the logger from the instance created from the IIndex but I was looking for some DI way to handle this.
I could also register my logger instance with my logmanager and have autofac inject the log manager into the processor but that seems like it is overly complex.
Any other ideas or anything would be great!
Thanks
Glenn
--
You received this message because you are subscribed to the Google Groups "Autofac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autofac+u...@googlegroups.com.
To post to this group, send email to aut...@googlegroups.com.
Visit this group at http://groups.google.com/group/autofac.
For more options, visit https://groups.google.com/d/optout.
That is great information and it worked perfectly, thanks for the detailed post.
If you happen to read this can you give a quick overview of why using IIndex is better to use than ResolveKeyed? The reason I ask is I use the ResolveKeyed I can add registrations in a scope which does not seem to work if I use the IIndex.
Example:
using (scope = mScope.BeginLifetimeScope(b => b.RegisterInstance(Of ILogger)(l))
{
var rr = scope.ResolveKeyed(Of IRealtime)(key)
}
The above gets all the necessary injections including the one ILogger I added in the nested scope.
Thanks
Glenn