© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
7 replies
TotechsStrypper

❔ Service layer design

This is my interface
using OneOf;
namespace petaverseapi;
public interface IAnimalService
{
    #region [ READS ]
    Task<IEnumerable<AnimalDTO>> FindAll(string consumerName, CancellationToken cancellationToken = default!);
    Task<AnimalDTO?> FindById(int id, string consumerName, CancellationToken cancellationToken = default!);
    Task<OneOf<IEnumerable<AnimalDTO>, ServiceError>> FindAllByUserGuid(string userGuid, string consumerName, CancellationToken cancellationToken = default!);
    #endregion

    #region [ MUTATES ]
    Task<OneOf<ServiceSuccess, ServiceError>> Create(CreatePetDTO dto, string consumerName, CancellationToken cancellationToken = default!);
    Task<OneOf<ServiceSuccess, ServiceError>> UploadAnimalMultiplePhotosAsync(int animalId, MediaTypeDTO mediaType, IFormFileCollection medias, string consumerName, CancellationToken cancellationToken = default!);


    Task<OneOf<ServiceSuccess, ServiceError>> UploadAnimalAvatarPhotoAsync(int animalId, IFormFile avatar, MediaTypeDTO type, string consumerName, CancellationToken cancellationToken = default!);
    Task<OneOf<ServiceSuccess, ServiceError>> UploadAnimalPhotoAsync(int animalId, IFormFile file, MediaTypeDTO type, string consumerName, CancellationToken cancellationToken = default!);
    Task<OneOf<ServiceSuccess, ServiceError>> Delete(int id, string consumerName, CancellationToken cancellationToken = default!);
    #endregion

}
using OneOf;
namespace petaverseapi;
public interface IAnimalService
{
    #region [ READS ]
    Task<IEnumerable<AnimalDTO>> FindAll(string consumerName, CancellationToken cancellationToken = default!);
    Task<AnimalDTO?> FindById(int id, string consumerName, CancellationToken cancellationToken = default!);
    Task<OneOf<IEnumerable<AnimalDTO>, ServiceError>> FindAllByUserGuid(string userGuid, string consumerName, CancellationToken cancellationToken = default!);
    #endregion

    #region [ MUTATES ]
    Task<OneOf<ServiceSuccess, ServiceError>> Create(CreatePetDTO dto, string consumerName, CancellationToken cancellationToken = default!);
    Task<OneOf<ServiceSuccess, ServiceError>> UploadAnimalMultiplePhotosAsync(int animalId, MediaTypeDTO mediaType, IFormFileCollection medias, string consumerName, CancellationToken cancellationToken = default!);


    Task<OneOf<ServiceSuccess, ServiceError>> UploadAnimalAvatarPhotoAsync(int animalId, IFormFile avatar, MediaTypeDTO type, string consumerName, CancellationToken cancellationToken = default!);
    Task<OneOf<ServiceSuccess, ServiceError>> UploadAnimalPhotoAsync(int animalId, IFormFile file, MediaTypeDTO type, string consumerName, CancellationToken cancellationToken = default!);
    Task<OneOf<ServiceSuccess, ServiceError>> Delete(int id, string consumerName, CancellationToken cancellationToken = default!);
    #endregion

}

and here are my the
ServiceSuccess
ServiceSuccess
and
ServiceError
ServiceError
basically they are just return information.
namespace petaverseapi;

public record ServiceSuccess(string ServiceName = "",
                             string MethodName = "",
                             string ConsumerName = "",
                             object? AttachedData = default!) : PetaverseSuccess;
namespace petaverseapi;

public record ServiceSuccess(string ServiceName = "",
                             string MethodName = "",
                             string ConsumerName = "",
                             object? AttachedData = default!) : PetaverseSuccess;

namespace petaverseapi;
public record ServiceError(string ServiceName = "", string MethodName = "", string ConsumerName = "") : PetaverseError;
namespace petaverseapi;
public record ServiceError(string ServiceName = "", string MethodName = "", string ConsumerName = "") : PetaverseError;

My question is for
FindAll
FindAll
,
FindById
FindById
and
FindAllByUserGuid
FindAllByUserGuid
should I return the same a the rest as
OneOf<ServiceSuccess, ServiceError>
OneOf<ServiceSuccess, ServiceError>
and attached the data in ?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Service Design
C#CC# / help
11mo ago
❔ Service Model Design - Nesting
C#CC# / help
3y ago
Snowflake Database Service Design Pattern
C#CC# / help
13mo ago
❔ Business Logic Validation in Service Layer
C#CC# / help
3y ago