0

ASP.NET MVC コントローラーに Ajax クエリを使用すると、エラーが発生します。

私のコード:

    //In My Controller

    private IDataService DataService;

    //I try to delete this constructor, 
    //because I use DI and don't want to create a CurrentContext and DataService.
    public MyController()
    {
       var CurrentContext = new CurrentContext();
       DataService = new DataService(CurrentContext);
    }

    public MyController(IDataService dataService)
    {
        DataService = dataService;
    }

    //In Autofac Init
    builder.RegisterType<DataService>().As <IDataService>();

この場合、どのように Autofac DI を使用できますか? お願い助けて。

更新:

//in Global.asax
DependencyConfigure.Initialize();

//in DependencyConfigure class
 public static void Initialize()
        {
            var builder = new ContainerBuilder();
            DependencyResolver.SetResolver(
                new Dependency(RegisterServices(builder))
                );
        }
4

0 に答える 0