我有以下扩展方法,它(自然地)存在于静态类中.
public static class MyExtensions
{
[Dependency]
private static IMyDataContext _myDataContext { get; set; }
public static void MyExtensionMethod(this MyType myType)
{
// do stuff
_myDataContext.DoAwesomeThing();
}
}
Run Code Online (Sandbox Code Playgroud)
该_myDataContext对象为null.
通常我会使用UnityContainer注册类型,但由于这是一个静态类,我不能.
我需要实例化_ myDataContext以便在需要时它不为空?