Show / Hide Table of Contents

Namespace StoneCo.Framework.Application.Extension

Classes

ModelResultExtension

Extension for IModelResult.

note

To simplify the examples and present actual use cases, a base code was created below.

Sample of the model Foo.

public class Foo : IAggregateRoot
{
    private Foo() { }

    public string Name { get; private set; }

    public static IModelResult<Foo> NewFoo(string name)
    {
        var foo = new Foo { Name = name };

        return Validate(foo);
    }

    private static IModelResult<Foo> Validate(Foo foo)
    {
        var result = new ModelResult<Foo>();

        if (string.IsNullOrWhiteSpace(foo.Name))
            result.AddValidation("Name", "The field is required");

        if (result.IsModelResultValid())
            result.SetModel(foo);

        return result;
    }
}

Sample of the request FooMessageRequest.

[DataContract(Namespace = "http://stone.com.br/type/")]
public class FooMessageRequest : RequestMessage
{

    [DataMember(Name = "name")]
    public string Name { get; set; }
}

Sample of the response FooMessageResponse.

[DataContract(Namespace = "http://stone.com.br/type/")]
public class FooMessageResponse : ResponseMessage
{

    [DataMember(Name = "name")]
    public string Name { get; set; }
}

Sample of the service layer with contract IFooService.

public interface IFooService
{
    IModelResult<Foo> CreateNew(string name);

    IModelResult ExecuteRuleOfFoo();

    IModelResult<Foo> GetFoo(string name);
}
Back to top Generated by DocFX