我的每个存储库类如下所示:
public class ProfileRepository : IProfileRepository{
private MyEntities myEnt = new MyEntities();
...
}
我正在注入我的存储库类,如下所示:
private static void RegisterServices(IKernel kernel)
{
kernel.Bind<IProfileRepository>().To<ProfileRepository>();
....
GlobalHost.DependencyResolver = new NinjectDependencyResolver(kernel);
GlobalHost.DependencyResolver.Register(typeof(IConnectionIdGenerator), () => new MyConnectionFactory());
RouteTable.Routes.MapHubs(new NinjectDependencyResolver(kernel));
}
我想将 MyEntities 上下文注入到我的所有存储库类中,因此我在每个存储库类中都没有它的实例。我该如何做到这一点?这会是更好的做法吗?