SoftStoneDevelop/Gedaq

AsPartInterface

SoftStoneDevelop opened this issue · 0 comments

Add info about generated methods as part of the interface.
For example, this can be useful if we want to separate commands and queries:

public class Person
{
    public int Id { get; set; }

    public string Name { get; set; }
}

publlic partial interface IPersonRepository : ICommandPersonRepository, IQueryPersonRepository
{
}

publlic partial interface ICommandPersonRepository
{
}

publlic partial interface IQueryPersonRepository
{
}
public partial class PersonRepository : IPersonRepository
{
[Query(
            @"
SELECT 
    p.id,
    p.name
FROM person p
",
            "GetAllPerson",
            typeof(Person),
            MethodType.Async,
            QueryType.Read,
            asPartInterface: typeof(IQueryPersonRepository)
            )]
    private GetAllPersonConfig()
    {
    }

[Query(
            @"
INSERT INTO person(
    id
)
VALUES (
    $1
)
",
            "AddPerson",
            typeof(Person),
            MethodType.Async,
            QueryType.NonQuery,
            asPartInterface: typeof(ICommandPersonRepository)
            ),
    Parametr(typeof(int), position: 1, methodParametrName: "id")
    ]
    private GetAllPersonConfig()
    {
    }
}
void SomewhereInCode(
    ICommandPersonRepository commands, 
    IQueryPersonRepository queries
)
{
    //commands.AddPersonAsync(...
    //queries.GetAllPersonAsync(...
}