Open Closed

How to use AppService directly in _Layout #1935

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)
  • 0
    ismcagdas created
    Support Team


    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.

  • 0
    kennywason created

    Thank you for your help!!!