Thanks Randy for your reply. I think the is what I am doing although my Logger is called SGLogger with its accompanying interface ISGLogger so maybe to be clearer I should rename it.
My concern is when working in Prism, when is it appropriate to inject in the container? Ok here is an overview of what I am doing specifically.
My solution has several projects.
- WPF project: This is where my bootstrapper is of course.
- ContentModule: This is a C# Library project that I inject the container into the constructor to resolve the Logger. So this is what the constructor looks like:
public ContentModuleMain(IUnityContainer container, IRegionManager regionManager) : base(container, regionManager)
this._container = container;
this._regionManager = regionManager;
this._logger = _container.Resolve<ISGLogger>();
Then I have a RegisterTypes method that registers my MainContentViewModel and my MainContentView types.
I also Register my Views with my Region and Resolve my VM's.
Ok, so at the Module level, I have a container dependency. But here is the question.
Here is the constructor for the ViewModel:
public MainContentViewModel(IMainContentView contentView,IUnityContainer container): base(contentView)
View = contentView;
_container = container;
_logger = _container.Resolve<ISGLogger>();
So again, I am passing into the VM the container in order to resolve my logger. I am not confident that this is the right approach just to get to the Logger. Is there another way without having a container dependency?
Note: the Logger has its own C# library and all of the interfaces are placed in a Util C# project for decoupling reasons.