У меня есть приложение веб-формы, в котором я хочу использовать внедрение зависимостей. Я следовал за этой статьей. Но при вызове этой функции он выдает ошибку нулевой ссылки.
private static object GetInstance(Type type)
{
// TODO: Get instance using your favorite DI library.
// for instance using the Common Service Locator:
return Microsoft.Practices.ServiceLocation
.ServiceLocator.Current.GetInstance(type);
}
Моя форма выглядит как
public partial class MenuTemplates : AdminBasePage
{
private readonly IMenuService _menuService;
private readonly ICryptography _cryptography;
protected MenuTemplates() { }
public MenuTemplates(
IMenuService menuService,
ICryptography cryptography
)
{
_menuService = menuService;
_cryptography = cryptography;
}}
Мой класс MenuService
public class MenuService : IMenuService
{
private readonly IMenuRepository _menuRepository;
private readonly IManagerService _managerService;
private readonly IEmployeeService _employeeService;
private readonly IQueryLibrary _queryLibrary;
private readonly Setting _setting;
public MenuService(
IMenuRepository menuRepository,
IManagerService managerService,
IEmployeeService employeeService,
IQueryLibrary queryLibrary,
Setting setting
)
{
_menuRepository = menuRepository;
_managerService = managerService;
_employeeService = employeeService;
_queryLibrary = queryLibrary;
_setting = setting;
}}
Мой интерфейс
public interface IMenuService
{
List<Item> GetMenuTypes();
string AdminName(long adminId);.... other functions}
Спасибо