Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How to use IIocResolver to resolve app service in controller #866


User avatar
0
winson created

I want to create the multiple pages project and not use angular script, so I want to call the app service directly in my controller, but I tried many ways and still failed, after I read the Dependency Injection , seems there is a way to resolve the service directly, but I still failed, below is my code:

app service:

private readonly IFormBuilderRepository _formBuilderRepository;

        public FormBuilderAppService(IFormBuilderRepository formBuilderRepository)
        {
            _formBuilderRepository = formBuilderRepository;
        }

in controller:

private readonly IIocResolver _iocResolver;

        public FormBuilderController(IIocResolver iocResolver)
        {
            _iocResolver = iocResolver;
        }

and in the action:

[HttpPost]
        [UnitOfWork]
        public JsonResult Index(FormBuilderInput formBuilder)
        {
            var _formBuilderAppService = _iocResolver.Resolve<IFormBuilderAppService>();
            _formBuilderAppService.Create(formBuilder);
            _iocResolver.Release(_formBuilderAppService);

            return Json(new { Name = formBuilder.Name });
        }

after run these code, I got the below error:

ABP The entity type FormBuilderModel is not part of the model for the current context.

I have no ideas :(


1 Answer(s)
  • User Avatar
    0
    winson created

    ok, I have resolved my problem, it's spend me a whole day, it maybe because my entity model name is not same with the database table name, when I drop the table and run update-database again, the problem is solved :(