question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Application service base class for CRUD operations

See original GitHub issue

What do you think about creating an application service base class or interface for CRUD operations

example:

public interface IEmployeesService : ICRUDService<EmployeeDto>
{
    public Create(EmployeeDTO employee){...}
}
...

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
hikalkancommented, Sep 14, 2016

Mini Documentation

An application service for Message entity which uses MessageDto as DTO for all methods:

public class MessageAppService : AsyncCrudAppService<Message, MessageDto>
{
    public MessageAppService(IRepository<Message> repository)
        : base(repository)
    {

    }
}

AsyncCrudAppService’s all methods are async. You can derive from CrudAppService if you prefer sync methods instead of async. MessageDto is like that:

[AutoMap(typeof(Message))]
public class MessageDto : FullAuditedEntityDto
{
    public int? TenantId { get; set; }

    public string Text { get; set; }
}

If you want to define interface for your application service:

public interface IMessageAppService : IAsyncCrudAppService<MessageDto>
{

}

Then you can implement IMessageAppService for MessageAppService without any code change.

In this sample, I used MessageDto for all methods. But we could specify CreateInput, UpdateInput, DeleteInput types and specify an input type for GetAll method (default input type is PagedAndSortedResultRequestInput, but your custom input type may not use paging/sorting). We can also override all base methods and customize mapping (which uses IObjectMapper by default).

0reactions
alexandiscommented, May 29, 2020

You can use https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp/Application/Services/AsyncCrudAppService.cs

Yes, I know 😃 but I already use CrudAppService, which is not -Async. Though, its methods are async-ready, so I want to have strong reason to rewrite my code to using AsyncCrudAppService

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I implement CRUD operations in a base class for ...
I've set up a BaseObject Class and a IBaseRepository Interface to handle the most basic operations so I don't have to repeat myself...
Read more >
[Updated] Building a Generic Service for CRUD Operations ...
In this article, we will explore how to create a generic service class in a C# .NET Core application to handle CRUD (Create,...
Read more >
CRUD Operations Using the Generic Repository Pattern ...
This article introduces use of the Generic Repository Pattern and Dependency Inversion Principle With IoC Container and DI in MVC for CRUD ......
Read more >
Creating a simple data-driven CRUD microservice
This section outlines how to create a simple microservice that performs create, read, update, and delete (CRUD) operations on a data source.
Read more >
application service documentation
The base CRUD class automatically checks permissions if you set them. Here, you can set it in the constructor: Copy. public class TaskAppService...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found