Conan.Net
Conan.Net

Reputation: 336

How to debug using UnityContainer Resolve?

0) How to debug unityContainer?

Im working on a legacy project on the firm, and all projects are loaded using dependency injection using unityContainer. I need to make improvements on the presentation layer, but I cannot debug the code, only the main project, witch loaded all modules.

The code used for loading modules(projects):

unityContainer.RegisterType("FrontEndModule", new InjectionMember[0]);

On the module, i register all project types like this:

unityContainer.RegisterType< IAboutPage, AboutPage>();

And then I run the main form:

Application.Run((Form) unityContainer.Resolve< IMainPage >() );

1) So there is any way to debug the code of the loaded projects?

2) Do I need to make any change to be able to debug? I've tried to run the form directly, but then there is a lot of injections needed to run. Maybe I would be able to use another IoC framework that permit me to debug the code of loaded projects.

Thanks.

Upvotes: 3

Views: 2941

Answers (1)

Alexei Levenkov
Alexei Levenkov

Reputation: 100547

There is nothing special about Unity when you debug code.

To be able to steps through the code you need

  • PDB files matching to DLLs that you are using (often it means "rebuild locally" unless PDB published along with DLLs)
  • source code, preferably matching the version of the source used to build DLLs (VS will allow to use mismatched sources, but you'll likely get very poor experience when stepping through does not match what actually happening since line numbers in PDB no longer align with actual text source)
  • you may need to disable "Tools->Options->Debug->My code only" setting to allow stepping through/breakpoints in code outside of solution (that's depending on VS mood :) )

If you can't get PDBs you still can see exceptions and call-stacks (as this information is part of DLL metainfo).

Switching to another DI framework will not have any impact on that.

Upvotes: 3

Related Questions