Reputation: 858
I am using the MVVM architecture and using prism in my application . following is the kind of code i used to set up IresourceManager. Please let me know whether this practice is good or should one go with Dependency Injection and pass the Resourcemanager every time inside the constructor as parameter.
public SapUploadScriptInfo(XDocument scriptDoc) : this()
{
this.resourceManager = ServiceLocator.Current.GetInstance<IResourceManagerService>();
this.scriptDoc = scriptDoc;
this.CreateFromXml(scriptDoc);
}
Now in order to unit test the class which is the best way 1. keep it as it is and unit test this method somewhere else (where it is being used again) 2. using DI approach.
Upvotes: 1
Views: 69
Reputation: 502
Now in order to unit test the class which is the best way 1. keep it as it is and unit test this method somewhere else (where it is being used again) > 2. using DI approach.
If you try to test this method elsewhere (as part of another function then calls it) then there are several issues :
As such i would recommend going with the dependancy injection approach. It immediately becomes clear what you're trying to do and it's easier to mock IResourcemanager if you had to and pass in an instance of it while running your test suite.
Upvotes: 2