Mtf.Web 1.0.2

dotnet add package Mtf.Web --version 1.0.2
                    
NuGet\Install-Package Mtf.Web -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Mtf.Web" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mtf.Web" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Mtf.Web" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Mtf.Web --version 1.0.2
                    
#r "nuget: Mtf.Web, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Mtf.Web@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Mtf.Web&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Mtf.Web&version=1.0.2
                    
Install as a Cake Tool

Mtf.Web.WebAPI Library Documentation

Overview

The Mtf.Web.WebAPI layer provides a generic, base implementation for ASP.NET Core controllers and DTO/model conversion. It includes:

  • ApiControllerBase<TDto, TModel, TIdType, TRepository, TConverter> A generic CRUD controller with virtual actions for Get, Create, Update, Delete.
  • ApiControllerBaseWithIntModelId<…> and ApiControllerBaseWithLongModelId<…> Specializations for integer- and long-typed model IDs.
  • IConverter<TModel, TDto> and BaseConverter<TModel, TDto> A standard interface and base class for shallow‐copying between models and DTOs.
  • PropertyCopier A helper for copying, including/excluding, or mapping properties via attributes.

Namespace: Mtf.Web.WebAPI

Class: ApiControllerBase<TDto, TModel, TIdType, TRepository, TConverter>

[ApiController]
[Route("api/[controller]")]
public abstract class ApiControllerBase<TDto, TModel, TIdType, TRepository, TConverter> 
    : ControllerBase
    where TIdType : struct
    where TDto     : IHaveIdWithSetter<TIdType>
    where TModel   : IHaveId<TIdType>
    where TRepository : IRepository<TModel>
    where TConverter  : IConverter<TModel, TDto>
{
    protected ILogger Logger { get; }
    protected TRepository Repository { get; }
    protected TConverter Converter { get; }

    protected ApiControllerBase(
        ILogger logger,
        TRepository repository,
        TConverter converter)
    { … }

    [HttpGet]
    public virtual ActionResult<IEnumerable<TDto>> GetAll() { … }

    [HttpGet("{id}")]
    public virtual ActionResult<TDto> GetById(TIdType id) { … }

    [HttpPost]
    public virtual ActionResult<TDto> Create(TDto dto) { … }

    [HttpPut("{id}")]
    public virtual IActionResult Update(TIdType id, TDto dto) { … }

    [HttpDelete("{id}")]
    public virtual IActionResult Delete(TIdType id) { … }

    protected abstract TModel Select(TIdType id);
}
  • Purpose: Exposes basic CRUD endpoints wired to a repository and converter.

  • Type Parameters:

    • TDto: DTO type (must have settable ID).
    • TModel: Domain model type (ID-getter).
    • TIdType: ID’s value type (e.g. int, long).
    • TRepository: Repository implementing IRepository<TModel>.
    • TConverter: Converter implementing IConverter<TModel,TDto>.
  • Key Methods:

    • GetAll(): GET → all records.
    • GetById(id): GET → record by ID.
    • Create(dto): POST → insert new.
    • Update(id, dto): PUT → update existing.
    • Delete(id): DELETE → remove.
    • Select(id): Abstract hook for fetching a single model.

Class: ApiControllerBaseWithIntModelId<TDto, TModel, TRepository, TConverter>

public abstract class ApiControllerBaseWithIntModelId<TDto, TModel, TRepository, TConverter>
    : ApiControllerBase<TDto, TModel, int, TRepository, TConverter>
    where TDto       : IHaveIdWithSetter<int>
    where TModel     : IHaveId<int>
    where TRepository : IRepository<TModel>
    where TConverter  : IConverter<TModel, TDto>
{
    protected ApiControllerBaseWithIntModelId(
        ILogger logger,
        TRepository repository,
        TConverter converter)
        : base(logger, repository, converter) { }

    protected override TModel Select(int id)
        => Repository.Select(id);
}
  • Specialization for int IDs.

Class: ApiControllerBaseWithLongModelId<TDto, TModel, TRepository, TConverter>

public abstract class ApiControllerBaseWithLongModelId<TDto, TModel, TRepository, TConverter>
    : ApiControllerBase<TDto, TModel, long, TRepository, TConverter>
    where TDto       : IHaveIdWithSetter<long>
    where TModel     : IHaveId<long>
    where TRepository : IRepository<TModel>
    where TConverter  : IConverter<TModel, TDto>
{
    protected ApiControllerBaseWithLongModelId(
        ILogger logger,
        TRepository repository,
        TConverter converter)
        : base(logger, repository, converter) { }

    protected override TModel Select(long id)
        => Repository.Select(id);
}
  • Specialization for long IDs.

Namespace: Mtf.Web.Interfaces

Interface: IConverter<TModel, TDto>

public interface IConverter<TModel, TDto>
{
    TDto ToDto(TModel model);
    TModel ToModel(TDto dto);
}
  • Purpose: Standard contract for converting between domain models and DTOs.

Namespace: LiveView.Web.Services

Class: BaseConverter<TModel, TDto>

public abstract class BaseConverter<TModel, TDto>
    : IConverter<TModel, TDto>
    where TModel : class, new()
    where TDto   : class, new()
{
    public virtual TDto ToDto(TModel model)
    {
        if (model == null) return null;
        var dto = new TDto();
        PropertyCopier.CopyMatchingProperties(model, dto);
        return dto;
    }

    public virtual TModel ToModel(TDto dto)
    {
        if (dto == null) return null;
        var model = new TModel();
        PropertyCopier.CopyMatchingProperties(dto, model);
        return model;
    }
}
  • Purpose: Implements shallow‐copy conversion using PropertyCopier.

Namespace: LiveView.Web.Services

Static Class: PropertyCopier

public static class PropertyCopier
{
    public static void CopyMatchingProperties<TSource, TTarget>(TSource source, TTarget target) { … }
    public static void CopyAllExceptExcluded<TSource, TTarget>(TSource source, TTarget target) { … }
    public static void CopyOnlyIncluded<TSource, TTarget>(TSource source, TTarget target) { … }
    public static void CopyWithMapping<TSource, TTarget>(
        TSource source,
        TTarget target,
        Func<PropertyInfo, bool> includeFilter = null) { … }
}
  • Methods:

    • CopyMatchingProperties: Copy all matching name/type props.
    • CopyAllExceptExcluded: Skip [Exclude]-marked props.
    • CopyOnlyIncluded: Copy only [Include]-marked props.
    • CopyWithMapping: Map via [Map] attributes & optional filter.

Example Usage

[ApiController]
[Route("api/widgets")]
public class WidgetController
    : ApiControllerBaseWithIntModelId<WidgetDto, WidgetModel, IWidgetRepo, WidgetConverter>
{
    public WidgetController(
        ILogger<WidgetController> logger,
        IWidgetRepo repo,
        WidgetConverter conv)
        : base(logger, repo, conv) { }
}
public class WidgetConverter : BaseConverter<WidgetModel, WidgetDto> { }

This gives you a ready-to-use controller with full CRUD behavior and model/DTO mapping out of the box.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 137 6/26/2025
1.0.1 134 6/25/2025