Closed artganify closed 8 years ago
Created a PR: #8
Thank you for the PR! Not a scenario I'd given any thought to.
I'm a bit rusty on how the MEF integration works - would you be able to give a code sample showing how the updated API is used?
Regards, Nick
Using the updated api, I can register the logger like so:
builder.RegisterLogger(configureRegistration: x => x.Export());
That way, the logger is being declared as an export and I can inject it into a resolved MEF component using Autofac.
However I think it would be good idea to have this API generally, because if I'm going to register a component within my IoC, I want at least to be able to define how the component is being registered. Maybe I need a special lifetime? Maybe I want to provide additional metadata?
Thanks for the follow-up! Makes sense.
It's a nice tidy PR, but given how small this project is I think it might be better in this case to grab the code and modify it in your own project. I'd like to keep the API of this one trivially simple, and I'm not sure exposing some of the implementation (i.e. generic arguments on IRegistrationBuilder<,,>
will hold up over time. Would this work for you?
Yup, works for me. I cannot say anything about the consequences of exposing the generic IRegistrationBuilder<,,>
, so this is probably for the best.
Thank you for your time. :)
Currently, this integration wraps everything required to resolve context-aware instances of
ILogger
from Autofac in a single Autofac module. While extremely convenient (it really doesn't get any easier thanbuilder.RegisterLogger()
), I'm currently facing the problem that I need to inject instances ofILogger
into imported MEF components (which are being resolved using Autofac with the Autofac.Integration.Mef package), however Autofac doesn't expose any dependencies for resolved MEF components unless they are declared as exports (usingIRegistrationBuilder<...>.Export()
). Which means I need to change howILogger
is being registered.Is there a way do to that with this integration? All I can see is that the extension method optionally takes an existing instance of
ILogger
or allows to declare whether properties are being autowired. And it returns aIModuleRegistrar
instead of aIRegistrationBuilder
, which is normally expected when registering components on theContainerBuilder
.