Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.
/ Message Public archive

Package that encapsulates responses between methods

License

Notifications You must be signed in to change notification settings

leo-oliveira-eng/Message

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📦 This repository has been archived and is no longer maintained.

Please note that this project is no longer supported or actively developed. The new and actively maintained repository can be found here: Funcfy

Message .NET Core License NuGet codecov CodeQL

This package encapsulates responses between methods preventing traffic from null objects in an application.

Installation

Message.Response.Maybe is available on NuGet. You can find the raw NuGet file here or install it by the commands below depending on your platform:

  • Package Manager
pm> Install-Package Message.Response.Maybe -Version 1.0.0
  • via the .NET Core CLI:
> dotnet add package Message.Response.Maybe --version 1.0.0
  • PackageReference
<PackageReference Include="Message.Response.Maybe" Version="1.0.0" />
  • PaketCLI
> paket add Message.Response.Maybe --version 1.0.0

Setup

There is no need to configure dependency injection. Just install it in the project you want to use.

How to Use

Maybe

When using a method that has the possibility of returning a null, the envelopment with Maybe indicates that the return must be verified, preventing the application from break down due to the absence of the object value.

public class RepositoryAsync<Entity> : SpecificMethods<Entity>, IRepositoryAsync<Entity>
{
   ...

   public async Task<Maybe<Entity>> FindAsync(int id)
     => await DbSet.FirstOrDefaultAsync(entity => entity.Id.Equals(id));
     
   ...
}

     

The developer can act as follows when receiving the response:

  ...

    var entity = await EntityRepository.FindAsync(entityId);

    if (!entity.HasValue)
        return response.WithBusinessError("Not found");

  ...

Response e Message

The response is not only intended to encapsulate the objects exchanged between the application's methods, but it also encapsulates information about the status of this response, error messages and can also indicate which was the property where the problem happened.

...

public static Response<Entity> Create(string name, string document)
{
     var response = Response<Entity>.Create();

     if (string.IsNullOrEmpty(name))
            response.WithBusinessError(nameof(name), $"{nameof(name)} is invalid");

     if (string.IsNullOrEmpty(document))
            response.WithBusinessError(nameof(role), $"{nameof(document)} is invalid");

     if (response.HasError)
         return response;

     return response.SetValue(new Entity(name, document));
}

...

License FOSSA Status

The project is under MIT License, so it grants you permission to use, copy, and modify a piece of this software free of charge, as is, without restriction or warranty.

FOSSA Status

About

Package that encapsulates responses between methods

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors 3

  •  
  •  
  •  

Languages