Working with Dapper (Part 3)

Empowered with a "template" to define the CRUDS interface method signatures, thanks to the ResultInfo class and .Net's dynamic types, I can quickly complete my interface designs.

The CRUD interfaces are pretty much the same.

using Mendz.Library;
using System.Collections.Generic;
using System.Dynamic;

namespace Mendz.Data
{
    public interface IDbDataCreatable<T>
    {
        T Create(T model, dynamic expansion, 
            out List<ResultInfo> returnValues);
    }

    public interface IDbDataReadable<T>
    {
        T Read(T model, dynamic expansion, 
            out List<ResultInfo> returnValues);
    }

    public interface IDbDataUpdatable<T>
    {
        T Update(T model, dynamic expansion, 
            out List<ResultInfo> returnValues);
    }

    public interface IDbDataDeletable<T>
    {
        T Delete(T model, dynamic expansion, 
            out List<ResultInfo> returnValues);
    }
}
This code defines the CRUD interfaces. The generic T is the type of the model that the method acts on. All of the CRUD methods accept the model itself as parameter. Likewise, all methods return an instance of the model's type. As planned, the expansion and returnValues parameters are always present.

The T model parameter can be a fully valued instance or a partially valued instance, depending on what is needed by the operation as input. The expansion parameter can be used for values that are not inherently supported by the model. This is useful in situations where the caller may add application defined fields that can influence the operation's behaviors or results -- examples: a flag to trap/ignore duplicates; a flag to cascade or not; or a date range to limit what to affect. As needed, the caller can use the returnValues to evaluate the call's results.

The S (or Search) interface on the other hand is unique.

using Mendz.Library;
using System;
using System.Collections.Generic;
using System.Dynamic;

namespace Mendz.Data
{
    public interface IDbDataSearchable<T>
    {
        IEnumerable<T> Search<F, S>(F filter, S sort, dynamic expansion,
            int page, int pageSize, out int totalCount, 
            out List<ResultInfo> returnValues);
    }
}
This code defines the search interface. The generic T is the type of the model that the method acts on. It accepts a filter and sort parameters, which can be caller defined types F and S, respectively. The expansion parameter is present as planned. It is followed by the pagination parameters: page (for the page number), pageSize (for the number of rows per page) and the output parameter totalCount (which can be used to help render "smart" pagination controls). As needed, the caller can use the returnValues to evaluate the call's results.

The CRUDS interfaces are now complete. Now it's time to sample them in repositories.

Comments