Service location
What is it?
Always go for IoC wherever possible
public class ManuallyInstantiatingDependencies
{
private ISomeDependency _someDependency;
public NotUsingIoC()
{ _someDependency = new SomeDependency(); }
public void DoSomething()
{ _someDependency.MakeTheMagic(); }
}using SomeDependencyContainer = SomeDependencyManager.Container;
public class UsingServiceLocation
{
private ISomeDependency _someDependency;
public UsingServiceLocation()
{ _someDependency = SomeDependencyContainer.Resolve<ISomeDependency>(); }
public void DoSomething()
{ _someDependency.MakeTheMagic(); }
}So is Service Location worth it?
Last updated