This project is read-only.

Dependency Injection doesn't seem to work across projects

Nov 21, 2012 at 4:55 AM

Hi there,

I have a main project with

public ICustomerAccount Customer_account { get; set; }

and in .Common project I have this

public class CustomerAccount : NotifyObject, ICustomerAccount

but the problem is this doesn't resolve, as soon as I move the CustomerAccount to the same project dependency is resolved properly,

Whats the fix?

Nov 21, 2012 at 5:33 AM
Edited Nov 21, 2012 at 5:42 AM

Hi zubairdotnet,

I'm guessing the problem is that you need to add a call in your app.xaml.cs to scan your other assembly for its exports.

There will be a line like the one below that registers your main assembly.


newBootstrapper.Container.RegisterAssembly( GetType().GetTypeInfo().Assembly); 


Add a new line like the one below (Note: after the existing register call but before the Start method call)

newBootstrapper.Container.RegisterAssembly( typeof(commonassembly.AnyType).GetTypeInfo().Assembly);

You can also create a registration class in your common assembly that has a static method that takes a container and registers the assembly. That way your main application only needs to call the static method at start up time and doesn't need to know about any other classes (i.e. classes you are exporting) but that's just a nice to have.




Nov 21, 2012 at 6:09 AM

Yes this was it,