Skip to content

Latest commit

 

History

History
101 lines (76 loc) · 3.3 KB

applicationservice.md

File metadata and controls

101 lines (76 loc) · 3.3 KB

Creating an Application Service

Using built-in CRUD application Service

public class EntityAppService : CrudAppService<Entity, EntityDto>
{
    public EntityAppService(IRepository<Entity> repository): base(repository)
}

Or as asynchronous

public class EntityAppService : AsyncCrudAppService<Entity, EntityDto>
{
    public EntityAppService(IRepository<Entity> repository): base(repository)
}

When overriding or extending the application service use the base repository Repository.

Injecting Domain Services

There are a couple of ways of injecting domain services (or even other application services, but this is not recommended). The dependency injector looks at the datatype passed (the interface or class name) to determine what to inject so the variable name can be anything you want.

Example: Injection via the Constructor

public class EntityAppService: projectAppServiceBase
{
    private readonly IEntityDomainService entityManager;

    public EntityAppService(
        IEntityDomainService entityManager
    )
    {
        this.entityManager = entityManager;
    }
    
    ...
}

Example: Injection via a Public Property

public class EntityAppService: projectAppServiceBase
{
    public IEntityDomainService EntityManager { get; set; }

    public EntityAppService()
    {
    }
    
    ...
}

Security

[AbpAuthorize(params string[] permissions)]

See User Manager, Roles & Permissions for more details.

Unit of Work

The UnitOfWorkManager is injected by default into MVC Controllers, application services & domain services. This means functions in an application service are transactional, i.e. if there's an exception in the function then all repository functions are rolled back.

It can be turned off by adding the UnitOfWork attribute to your function and setting IsDisabled to true. However, if a unit of work function calls a function where the unit of work is disabled, the disable is ignored and it will use the same connection & transaction.

[UnitOfWork(IsDisabled: true)]

You can also use Unit of Work to impersonate another tenant

using (_unitOfWorkManager.Current.SetTenantId(input.TentantId))
{
} 

Hide from Controller

The .Web.Core module is configured to generate WebAPI controllers for any application services found in .Application. To prevent a specific application service or function in a service from being generated, add the RemoteService attibute and set isEnabled to false.

[RemoteService(isEnabled: false)]

Function Names

HTTP verbs are determined by method name prefixes, otherwise Post is used as default HTTP verb. You can also override or specify a preferred method using the the HTTP-verb attributes found in Microsoft.AspNet.WebApi.Core.

  • Get: Used if method name starts with 'Get'.
  • Put: Used if method name starts with 'Put' or 'Update'.
  • Delete: Used if method name starts with 'Delete' or 'Remove'.
  • Post: Used if method name starts with 'Post', 'Create' or 'Insert'.
  • Patch: Used if method name starts with 'Patch'.

See Also