I have a windows service and I’m injecting a module to it:
private ICoupon _couponManager;
...
DirectoryCatalog catalog = new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins"));
_container = new CompositionContainer(catalog);
_couponManager = _container.GetExportedValue<ICoupon>();// Here I'm getting an exception
But the module that I’m trying to import is an constructer injected module:
[Import(typeof(IWallet))]
private IWallet _iWallet;
private static CompositionContainer _container;
public CouponManager()
{
DirectoryCatalog catalog = new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins"));
_container = new CompositionContainer(catalog);
_container.ComposeParts();
}
So I’m getting “An exception occurred while trying to create an instance of type ‘X.Business.CouponManager’.” error. How do I have to inject my module?
I’m not sure if my question is clear, if not please ask for details.
Thanks in advance,
Edit: The interesting part is: I can inject this module to my asp.net mvc application and use it without problem.
in addition to Gilles answer your class should look like this