Nop.Services.Customers.CustomerServiceに静的関数を作成してgetを取得しようとしています
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();
}
しかし、この関数を呼び出すと、nullエラーが表示されます。
Nop.Coreで関数を作成して外部アプリケーションを呼び出すことはできませんか?
助けてください。