As far as I know, DependencyResolver is thread safe, however running the following code will throw a link in the background thread.
public interface ITest {
}
public class Test : ITest {
}
var service = DependencyResolver.Current.GetService<ITest>();
var t1 = Task.Run(() => {
var s1 = DependencyResolver.Current.GetService<ITest>();
});
Task.WaitAll(t1);
Here's the stack trace:
at Unity.Mvc4.UnityDependencyResolver.get_ChildContainer()
at Unity.Mvc4.UnityDependencyResolver.IsRegistered(Type typeToCheck)
at Unity.Mvc4.UnityDependencyResolver.GetService(Type serviceType)
at System.Web.Mvc.DependencyResolverExtensions.GetService[TService](IDependencyResolver resolver)
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
I know that the "Service Locator" template is an anti-template. At the moment, I'm just trying to understand why this is not working.
Any ideas would be appreciated.
Thank!
source
share