private static ICartRepository _CartRepository;
private static IProductService _ProductService;
private static IUserService _UserService;
public DomainRegistry(ICartRepository CartRepository, IProductService ProductService, IUserService UserService)
{
_CartRepository = CartRepository;
_ProductService = ProductService;
_UserService = UserService;
}
public static ICartRepository CartService()
{
return _CartRepository;
}为什么调用CartService()方法时,_CartRepository调试时一直为null,构造函数没执行吗?
构造函数!=静态构造函数
什么意思,我这不是静态构造函数啊
知道了,我定义的是static ICartRepository _CartRepository;是这个吗?应该用静态构造函数?
改了还是不行啊
@灬丶: public static ICartRepository CartService()-> public ICartRepository CartService()
这样改是最块的方法.
@吴瑞祥: 这个我知道,但是我想知道怎么对这个全局静态成员赋值
@灬丶: 写个静态构造函数啊.
CartService()这个是静态方法,由类本身提供,和里面的对象半毛钱关系没有呀
不是应该初始化嘛
结合在一起
public static ICartRepository CartService(ICartRepository CartRepository, IProductService ProductService, IUserService UserService)
{
DomainRegistry(CartRepository,ProductService,UserService)
return _CartRepository;
}