Skip to content

sourcecode

devonfw-core edited this page Jun 6, 2022 · 1 revision

Source code and structure

Architecture layer implementation

The figure below displays how the devon4Net WebAPI template implements the architecture described in the previous section:

devon4Net api template architecture implementation
Figure 1. devon4Net architecture implementation

Communication between Layers: Interfaces

The main objective of using interfaces is to loosen coupling between layers between layers and minimize dependencies.

Public interfaces allow to hide implementation details of the components within the layers making use of dependency inversion.

In order to make this possible, we make use of Dependency Injection Pattern (implementation of dependency inversion) given by default in .Net.

The abstract classes to inherit from are contained in the given Domain Layer. All new repository and service classes must inherit from them and implement their own interfaces.

technical architecture
Figure 2. Architecture representation in deep

Domain layer implementation

To make a good use of this technology, Repository Pattern has been implemented with the help of Unit Of Work pattern. Also, the use of generic types are makes this solution to be the most flexible.

 public class UnitOfWork<TContext> : IUnitOfWork<TContext> where TContext : DbContext, IDisposable
Note
Where <T> is the mapped class which reference the entity from the database.

We also employ IDisposable, which is mostly used to release unmanaged resources. Use this interface’s Dispose method to explicitly release unmanaged resources in conjunction with the garbage collector.

Regarding to data base source, each entity is mapped as a class. Repository pattern allows to use this mapped classes to access the data base via Entity framework.

In order to implement the repository logic, the repository class must follow the following specifications:

    Repository<T> : IRepository<T> where T : class
Note
Please remember that <T> is the mapped class which reference the entity from the database context. This abstraction allows to write services implementation with different database contexts

The repository and unit of work patterns form an abstraction layer between the data access layer and the business logic layer of an application.

Data layer Implementation

devon4Net WebAPI template shows how to implement the TODOs repository as follows:

    public class TodoRepository : Repository<Todos>, ITodoRepository

Where Repository is the the base repository class to be inherited and have full access for the basic CRUD operations, Todos is the entity defined in the database context. ITodoRepository is the interface of the repository, which exposes the public extended methods to be implemented.

Business layer implementation

In order to implement the service logic, the services class must follow the next specification:

    public class Service<TContext> : IService where TContext: DbContext

PE: devon4Net WebAPI template shows how to implement the TODOs service as follows:

    public class TodoService: Service<TodoContext>, ITodoService

Where Service is the base service class to be inherited and have full access for the Unit of work, TodoContext is the TODOs database context and ITodoService is the interface of the service, which exposes the public extended methods to be implemented.

Cross-Cutting concerns

Cross-cutting offers layer-spanning implementation functionality. Each feature is provided using stand-alone components. This approach enhances reusability and maintainability.

A common component set of cross-cutting components include different types of functionality regarding to authentication, authorization, security, caching, configuration, logging, and communication.

Templates

State of the art

The provided bundle contains the devon4Net WebAPI template based on .Net core. The template allows to create a microservice solution with minimal configuration.

In addition, the devon4net framework may be integrated to third-party templates such as the Amazon API template to enable the usage of lambdas in serverless environments.

Included features:

  • Logging:

    • Text File

    • Sqlite database support

    • Serilog Seq Server support

    • Graylog integration ready through TCP/UDP/HTTP protocols

    • API Call params interception (simple and compose objects)

    • API error exception management

  • Swagger:

    • Swagger autogenerating client from comments and annotations on controller classes

    • Full swagger client customization (Version, Title, Description, Terms, License, Json end point definition)

    • Easy configuration with just one configuration node in your settings file

  • JWT:

    • Issuer, audience, token expiration customization by external file configuration

    • Token generation via certificate

    • MVC inherited classes to access JWT user properties

    • API method security access based on JWT Claims

  • CORS:

    • Simple CORS definition ready

    • Multiple CORS domain origin definition with specific headers and verbs

  • Headers:

    • Automatic header injection with middleware.

    • Supported header definitions: AccessControlExposeHeader, StrictTransportSecurityHeader, XFrameOptionsHeader, XssProtectionHeader, XContentTypeOptionsHeader, ContentSecurityPolicyHeader, PermittedCrossDomainPoliciesHeader, ReferrerPolicyHeader

  • Reporting server:

    • Partial implementation of reporting server based on My-FyiReporting (now runs on linux container)

  • Testing:

    • Integration test template with sqlite support

    • Unit test template

    • Moq, xunit frameworks integrated

  • Circuit breaker:

    • Integrated with HttpClient factory

    • Client Certificate customization

    • Number of retries customizables

  • LiteDB:

    • Support for LiteDB

    • Provided basic repository for CRUD operations

  • RabbitMq:

    • Use of EasyQNet library to perform CQRS main functions between different microservices

    • Send commands / Subscribe queues with one C# sentence

    • Events management: Handled received commands to subscribed messages

    • Automatic messaging backup when sent and handled (Internal database via LiteDB and database backup via Entity Framework)

  • MediatR:

    • Use of MediatR library to perform CQRS main functions in memory

    • Send commands / Subscribe queues with one C# sentence

    • Events management: Handled received commands to subscribed messages

    • Automatic messaging backup when sent and handled (Internal database via LiteDB and database backup via Entity Framework)

  • SmaxHcm:

    • Component to manage Microfocus SMAX for cloud infrastructure services management

  • CyberArk:

    • Manage safe credentials with CyberArk

  • AnsibleTower:

    • Ansible automates the cloud infrastructure. devon4net integrates with Ansible Tower via API consumption endpoints

  • gRPC+Protobuf:

    • Added Client + Server basic templates sample gRPC with Google’s Protobuf protocol using devon4net

  • Kafka:

    • Added Apache Kafka support for deliver/consume messages and create/delete topics as well

Target platforms

Thanks to the new .Net Core platform from Microsoft, the developed software can be published Windows, Linux, OS, X and Android platforms.