WIP Clean Architecture

Windows 8.1 App Uses keepasslib v2.44 (temporarily)
This commit is contained in:
Geoffroy BONNEVILLE
2020-03-24 13:01:14 +01:00
parent 34cd4ca3d8
commit 7e44d47065
290 changed files with 4084 additions and 36416 deletions

View File

@@ -0,0 +1,10 @@
using AutoMapper;
namespace ModernKeePass.Application.Common.Mappings
{
public interface IMapFrom<T>
{
void Mapping(Profile profile);
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Linq;
using System.Reflection;
using AutoMapper;
namespace ModernKeePass.Application.Common.Mappings
{
public class MappingProfile : Profile
{
public MappingProfile()
{
ApplyMappingsFromAssembly(Assembly.GetExecutingAssembly());
}
private void ApplyMappingsFromAssembly(Assembly assembly)
{
var types = assembly.GetExportedTypes()
.Where(t => t.GetInterfaces().Any(i =>
i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IMapFrom<>)))
.ToList();
foreach (var type in types)
{
var instance = Activator.CreateInstance(type);
var methodInfo = type.GetMethod("Mapping");
methodInfo?.Invoke(instance, new object[] { this });
}
}
}
}

View File

@@ -0,0 +1,17 @@
using AutoMapper;
using ModernKeePass.Application.Database.Models;
using ModernKeePass.Application.Entry.Models;
using ModernKeePass.Application.Group.Models;
namespace ModernKeePass.Application.Common.Mappings
{
public class MappingProfiles: Profile
{
public void ApplyMappings()
{
new DatabaseVm().Mapping(this);
new EntryVm().Mapping(this);
new GroupVm().Mapping(this);
}
}
}