Base solution for your next web application
Open Closed

How to use AppService directly in _Layout #1935


User avatar
0
jsluong created

I have ITaskAppService & TaskAppService.

I'm planing to use TaskAppService in my _Layout.cshtml view, but doesn't know how to create an instant of it.

Should I use ITaskAppService task = new TaskAppService()?

Please help me out.

Thank you!


2 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    There must be a [*ViewBase] class in your Web project under Views folder. Add a property to it like this.

    public ITaskAppService TaskAppService { get; private set; }
    

    then set it in the constructor of your ViewBase's constructor like this.

    TaskAppService = IocManager.Instance.Resolve<ITaskAppService>();
    

    Then you should be able to use @TaskAppService in your cshtml files.

  • User Avatar
    0
    kennywason created

    Thank you for your help!!!