-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from rena0157/develop
Release of 0.3.0
- Loading branch information
Showing
17 changed files
with
310 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
mode: ContinuousDelivery | ||
next-version: 0.2.0 | ||
next-version: 0.3.0 | ||
branches: {} | ||
ignore: | ||
sha: [] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Sample Map App | ||
|
||
The purpose of this sample app is to present the intended use and setup of Mapr. | ||
|
||
It consists of four parts: | ||
|
||
1. A `Domain` folder that contains the domain models | ||
2. A `DataModels` folder that contains DTOs (Normally this would be in different project.) | ||
3. A `Maps` folder that contains the maps for the models and DTOs | ||
4. A `Program.cs` file that configures and uses the `IMapper`. | ||
|
||
The example domain object is a `Person` class. It contains a couple of properties as well as a | ||
value object `Address`, which also contains some properties and another value object `ZipCode`. | ||
|
||
The `Maps` folder contains the definitions for the mapping between the domain models and the | ||
DTOs. Note that the `IMapper` interface is injected into the mapper. This allows you to map | ||
more complex objects such as `Person` that in tern contains objects that need to be mapped. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.26124.0 | ||
MinimumVisualStudioVersion = 15.0.26124.0 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{593B8499-9DF8-41FC-9CFB-A0232413FA02}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleMapperApp.ConsoleApp", "src\SampleMapperApp.ConsoleApp\SampleMapperApp.ConsoleApp.csproj", "{24A13F15-49C6-4658-8757-B7A2CD4E291B}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{24A13F15-49C6-4658-8757-B7A2CD4E291B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{24A13F15-49C6-4658-8757-B7A2CD4E291B}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{24A13F15-49C6-4658-8757-B7A2CD4E291B}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{24A13F15-49C6-4658-8757-B7A2CD4E291B}.Debug|x64.Build.0 = Debug|Any CPU | ||
{24A13F15-49C6-4658-8757-B7A2CD4E291B}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{24A13F15-49C6-4658-8757-B7A2CD4E291B}.Debug|x86.Build.0 = Debug|Any CPU | ||
{24A13F15-49C6-4658-8757-B7A2CD4E291B}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{24A13F15-49C6-4658-8757-B7A2CD4E291B}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{24A13F15-49C6-4658-8757-B7A2CD4E291B}.Release|x64.ActiveCfg = Release|Any CPU | ||
{24A13F15-49C6-4658-8757-B7A2CD4E291B}.Release|x64.Build.0 = Release|Any CPU | ||
{24A13F15-49C6-4658-8757-B7A2CD4E291B}.Release|x86.ActiveCfg = Release|Any CPU | ||
{24A13F15-49C6-4658-8757-B7A2CD4E291B}.Release|x86.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{24A13F15-49C6-4658-8757-B7A2CD4E291B} = {593B8499-9DF8-41FC-9CFB-A0232413FA02} | ||
EndGlobalSection | ||
EndGlobal |
15 changes: 15 additions & 0 deletions
15
samples/SampleMapperApp/src/SampleMapperApp.ConsoleApp/DataModels/AddressModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
namespace SampleMapperApp.ConsoleApp.DataModels | ||
{ | ||
public class AddressModel | ||
{ | ||
public int PersonId { get; set; } | ||
|
||
public string StreetNumber { get; set; } | ||
|
||
public string StreetName { get; set; } | ||
|
||
public string ZipCode { get; set; } | ||
|
||
public string Country { get; set; } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
samples/SampleMapperApp/src/SampleMapperApp.ConsoleApp/DataModels/PersonModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace SampleMapperApp.ConsoleApp.DataModels | ||
{ | ||
public class PersonModel | ||
{ | ||
public int Id { get; set; } | ||
|
||
public string FirstName { get; set; } | ||
|
||
public string LastName { get; set; } | ||
|
||
public AddressModel AddressModel { get; set; } | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
samples/SampleMapperApp/src/SampleMapperApp.ConsoleApp/Domain/Address.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
namespace SampleMapperApp.ConsoleApp.Domain | ||
{ | ||
public class Address | ||
{ | ||
public Address(string streetNumber, string streetName, ZipCode zipCode, string country) | ||
{ | ||
// Validation ... | ||
StreetNumber = streetNumber; | ||
StreetName = streetName; | ||
ZipCode = zipCode; | ||
Country = country; | ||
} | ||
|
||
public string StreetNumber { get; } | ||
|
||
public string StreetName { get; } | ||
|
||
public ZipCode ZipCode { get; } | ||
|
||
public string Country { get; } | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
samples/SampleMapperApp/src/SampleMapperApp.ConsoleApp/Domain/Person.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
namespace SampleMapperApp.ConsoleApp.Domain | ||
{ | ||
public class Person | ||
{ | ||
public Person(int id, string firstName, string lastName, Address address) | ||
{ | ||
// Validation... | ||
Id = id; | ||
FirstName = firstName; | ||
LastName = lastName; | ||
Address = address; | ||
} | ||
|
||
public int Id { get; } | ||
|
||
public string FirstName { get; } | ||
|
||
public string LastName { get; } | ||
|
||
public Address Address { get; } | ||
|
||
public string FullName => $"{FirstName} {LastName}"; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
samples/SampleMapperApp/src/SampleMapperApp.ConsoleApp/Domain/ZipCode.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace SampleMapperApp.ConsoleApp.Domain | ||
{ | ||
public class ZipCode | ||
{ | ||
public ZipCode(string value) | ||
{ | ||
// Validation... | ||
Value = value; | ||
} | ||
|
||
public string Value { get; } | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
samples/SampleMapperApp/src/SampleMapperApp.ConsoleApp/Maps/AddressMap.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Mapr; | ||
using SampleMapperApp.ConsoleApp.DataModels; | ||
using SampleMapperApp.ConsoleApp.Domain; | ||
|
||
namespace SampleMapperApp.ConsoleApp.Maps | ||
{ | ||
public class AddressMap : IMap<(Address address, int personId), AddressModel>, IMap<AddressModel, Address> | ||
{ | ||
private readonly IMapper _mapper; | ||
|
||
public AddressMap(IMapper mapper) | ||
{ | ||
_mapper = mapper; | ||
} | ||
|
||
public Address Map(AddressModel source) | ||
{ | ||
var zipCode = _mapper.Map<string, ZipCode>(source.ZipCode); | ||
return new Address(source.StreetNumber, source.StreetName, zipCode, source.Country); | ||
} | ||
|
||
public AddressModel Map((Address address, int personId) source) | ||
{ | ||
var (address, personId) = source; | ||
return new() | ||
{ | ||
PersonId = personId, | ||
StreetName = address.StreetName, | ||
Country = address.Country, | ||
StreetNumber = address.StreetNumber, | ||
ZipCode = _mapper.Map<ZipCode, string>(address.ZipCode) | ||
}; | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
samples/SampleMapperApp/src/SampleMapperApp.ConsoleApp/Maps/PersonMap.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Mapr; | ||
using SampleMapperApp.ConsoleApp.DataModels; | ||
using SampleMapperApp.ConsoleApp.Domain; | ||
|
||
namespace SampleMapperApp.ConsoleApp.Maps | ||
{ | ||
public class PersonMap : IMap<Person, PersonModel>, IMap<PersonModel, Person> | ||
{ | ||
private readonly IMapper _mapper; | ||
|
||
public PersonMap(IMapper mapper) | ||
{ | ||
_mapper = mapper; | ||
} | ||
|
||
public PersonModel Map(Person source) | ||
{ | ||
return new PersonModel | ||
{ | ||
Id = source.Id, | ||
FirstName = source.FirstName, | ||
LastName = source.LastName, | ||
|
||
// Calling the mapper to map the address to the model. | ||
AddressModel = _mapper.Map<Address, AddressModel>(source.Address) | ||
}; | ||
} | ||
|
||
public Person Map(PersonModel source) | ||
{ | ||
// Convert the address model back to an address. | ||
var address = _mapper.Map<AddressModel, Address>(source.AddressModel); | ||
|
||
return new Person(source.Id, source.FirstName, source.LastName, address); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
samples/SampleMapperApp/src/SampleMapperApp.ConsoleApp/Maps/ZipCodeMap.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Mapr; | ||
using SampleMapperApp.ConsoleApp.Domain; | ||
|
||
namespace SampleMapperApp.ConsoleApp.Maps | ||
{ | ||
public class ZipCodeMap : IMap<ZipCode, string>, IMap<string, ZipCode> | ||
{ | ||
public string Map(ZipCode source) | ||
{ | ||
return source.Value; | ||
} | ||
|
||
public ZipCode Map(string source) | ||
{ | ||
return new(source); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
samples/SampleMapperApp/src/SampleMapperApp.ConsoleApp/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using Mapr; | ||
using Mapr.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using SampleMapperApp.ConsoleApp.DataModels; | ||
using SampleMapperApp.ConsoleApp.Domain; | ||
|
||
|
||
var services = new ServiceCollection(); | ||
|
||
services.AddMapr(config => | ||
{ | ||
config.Scan(typeof(Person).Assembly); | ||
}); | ||
|
||
var provider = services.BuildServiceProvider(); | ||
|
||
var mapper = provider.GetRequiredService<IMapper>(); | ||
|
||
var address = new Address("123", "Fake Street", new ZipCode("90120"), "USA"); | ||
var person = new Person(1, "John", "Smith", address); | ||
|
||
var personModel = mapper.Map<Person, PersonModel>(person); |
14 changes: 14 additions & 0 deletions
14
samples/SampleMapperApp/src/SampleMapperApp.ConsoleApp/SampleMapperApp.ConsoleApp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Mapr" Version="0.2.0" /> | ||
<PackageReference Include="Mapr.DependencyInjection" Version="0.2.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.