我尝试在Nop.Services.Customers.CustomerService中创建一个静态函数以获取
nop 数据库中的客户列表。我想在外部控制台中调用此函数
应用。但是CustomerService 类不包含默认构造函数。
请参阅构造函数代码。
#region Ctor
/// <summary>
/// Ctor
/// </summary>
/// <param name="cacheManager">Cache manager</param>
/// <param name="customerRepository">Customer repository</param>
/// <param name="customerRoleRepository">Customer role repository</param>
/// <param name="customerAttributeRepository">Customer attribute repository</param>
/// <param name="encryptionService">Encryption service</param>
/// <param name="newsLetterSubscriptionService">Newsletter subscription service</param>
/// <param name="rewardPointsSettings">Reward points settings</param>
/// <param name="customerSettings">Customer settings</param>
/// <param name="eventPublisher"></param>
public CustomerService(ICacheManager cacheManager,
IRepository<Customer> customerRepository,
IRepository<CustomerRole> customerRoleRepository,
IRepository<CustomerAttribute> customerAttributeRepository,
IEncryptionService encryptionService, INewsLetterSubscriptionService newsLetterSubscriptionService,
RewardPointsSettings rewardPointsSettings, CustomerSettings customerSettings,
IEventPublisher eventPublisher)
{
_cacheManager = cacheManager;
_customerRepository = customerRepository;
_customerRoleRepository = customerRoleRepository;
_customerAttributeRepository = customerAttributeRepository;
_encryptionService = encryptionService;
_newsLetterSubscriptionService = newsLetterSubscriptionService;
_rewardPointsSettings = rewardPointsSettings;
_customerSettings = customerSettings;
_eventPublisher = eventPublisher;
}
#endregion
Fileds 在尝试调用静态函数时会显示错误。
请查看字段
#region Fields
private readonly IRepository<Customer> _customerRepository;
private readonly IRepository<CustomerRole> _customerRoleRepository;
private readonly IRepository<CustomerAttribute> _customerAttributeRepository;
private readonly IRepository<FileUpload> _fileuploadRepository;
private readonly IEncryptionService _encryptionService;
private readonly ICacheManager _cacheManager;
private readonly INewsLetterSubscriptionService _newsLetterSubscriptionService;
private readonly RewardPointsSettings _rewardPointsSettings;
private readonly CustomerSettings _customerSettings;
private readonly IEventPublisher _eventPublisher;
#endregion
我在 CustomerService 类中创建了一个默认值。
public CustomerService()
{
}
并在 CustomerService 中创建新功能
public virtual List<Customer> GetClients()
{
var _cust = _customerRepository.Table;
return _cust.ToList();
}
并在外部控制台应用程序中调用此函数
private static CustomerService _customerService = new CustomerService();
static void Main(string[] args)
{
List<Customer> cust = _customerService.GetClients();
ThreadStart start = new ThreadStart(ProcessMails);
thread = new Thread(start);
ProcessStatus = 1;
thread.Start();
}
但是当我调用这个函数时,它会显示空错误。
不能在 Nop.Core 中创建函数并调用外部应用程序吗?
请帮忙。