简体   繁体   中英

How do I get ABP Application Service routing to multiple implementations?

I am using ASP.NET Boilerplate (ABP).

I want to have a generic application service that is implemented in multiple ways. Reading the documentation, it appears that it requires me to create an interface for each class. I want to have one generic interface and be able to route it to the implemented classes. Is there any way to do this?

public interface IMyAppService : IApplicationService
{
    Task<DataTableCollection> PostData(string action, string data);
}

public class myclass1 : IMyAppService
{
    public async Task<DataTableCollection> PostData(string action, string data)
    {
        ...
    }
}

public class myclass2 : IMyAppService
{
    public async Task<DataTableCollection> PostData(string action, string data)
    {
        ...
    }
}

And then in my application, access them via routes like /app/myclass1 and /app/myclass2 .

That should already work. The interface for each class is recommended (though not necessary) for Dependency Injection, but that's irrelevant here.

You just need to implement the IApplicationService Interface .

If you are doing this to generalize CRUD operations, there's already such an interface AsyncCrudAppService

public class TaskAppService : AsyncCrudAppService<Task, TaskDto>, ITaskAppService
{
    public TaskAppService(IRepository<Task> repository) 
        : base(repository)
    {

    }
}

https://aspnetboilerplate.com/Pages/Documents/Application-Services#crudappservice-and-asynccrudappservice-classes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM