Skip to content

Commit 11f88b4

Browse files
committed
Merge branch 'development' into feature/sqs
2 parents 03d88f7 + 8957215 commit 11f88b4

File tree

485 files changed

+5688
-1520
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

485 files changed

+5688
-1520
lines changed

Modules/Intent.Modules.Application.DomainInteractions/DataAccessProviders/DbContextDataAccessProvider.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
using System.Collections.Generic;
2-
using System.Linq;
31
using Intent.Exceptions;
42
using Intent.Metadata.Models;
53
using Intent.Modelers.Domain.Api;
4+
using Intent.Modules.Common;
65
using Intent.Modules.Common.CSharp.Builder;
76
using Intent.Modules.Common.CSharp.Interactions;
87
using Intent.Modules.Common.CSharp.Mapping;
98
using Intent.Modules.Common.CSharp.Templates;
109
using Intent.Modules.Common.Templates;
1110
using Intent.Modules.Constants;
11+
using System.Collections.Generic;
12+
using System.Linq;
13+
using System.Threading;
14+
using static Intent.Modules.Constants.TemplateRoles.Domain;
1215

1316
namespace Intent.Modules.Application.DomainInteractions.DataAccessProviders;
1417

@@ -32,7 +35,9 @@ public DbContextDataAccessProvider(
3235
_dbContextField = dbContextField;
3336
_template = template;
3437
_mappingManager = mappingManager;
35-
_dbSetAccessor = new CSharpAccessMemberStatement(_dbContextField, entity.Name.ToPascalCase().Pluralize());
38+
39+
_dbSetAccessor = new CSharpAccessMemberStatement(_dbContextField, GetDbSetName(entity));
40+
3641
var entityTemplate = _template.GetTemplate<ICSharpFileBuilderTemplate>(TemplateRoles.Domain.Entity.Primary, entity);
3742
_pks = entityTemplate.CSharpFile.Classes.First().GetPropertiesWithPrimaryKey();
3843
_isUsingProjections = queryContext?.ImplementWithProjections() == true;
@@ -294,4 +299,14 @@ public CSharpStatement FindAllAsync(IElementToElementMapping queryMapping, strin
294299
prerequisiteStatements = new List<CSharpStatement>();
295300
return new CSharpStatement("");
296301
}
302+
303+
public string GetDbSetName(ClassModel model)
304+
{
305+
if (_template.ExecutionContext.Settings.GetSetting("ac0a788e-d8b3-4eea-b56d-538608f1ded9", "6010e890-6e2d-4812-9969-ffbdb8f93d87")?.Value == "same-as-entity")
306+
{
307+
return model.Name.ToPascalCase();
308+
}
309+
310+
return model.Name.ToPascalCase().Pluralize();
311+
}
297312
}

Modules/Intent.Modules.Application.DomainInteractions/Extensions/DomainInteractionExtensions.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ public static IEnumerable<CSharpStatement> GetReturnStatements(this CSharpClassM
288288
}
289289
var statements = new List<CSharpStatement>();
290290

291-
var mapperIsInstalled = method.File.Template.ExecutionContext.InstalledModules.Any(x => x.ModuleId == "Intent.Application.Dtos.AutoMapper"
292-
|| x.ModuleId == "Intent.Application.Dtos.Mapperly");
291+
var mapperIsInstalled = MappingStrategyProvider.Instance.HasMappingStrategy(method);
293292

294293
var template = method.File.Template;
295294
var entitiesReturningPk = GetEntitiesReturningPk(method, returnType);
@@ -303,7 +302,7 @@ public static IEnumerable<CSharpStatement> GetReturnStatements(this CSharpClassM
303302
var entityDetails = method.TrackedEntities().Values.First(x => x.ElementModel?.Id == returnType.Element.AsDTOModel().Mapping.ElementId);
304303
if (entityDetails.ProjectedType == returnDto)
305304
{
306-
statements.Add($"return {entityDetails.VariableName};");
305+
statements.Add(new CSharpReturnStatement(entityDetails.VariableName));
307306
}
308307
else
309308
{
@@ -322,14 +321,13 @@ public static IEnumerable<CSharpStatement> GetReturnStatements(this CSharpClassM
322321
var entityDetails = method.TrackedEntities().Values.First(x => x.ElementModel.Id == returnType.GenericTypeParameters.First().Element.AsDTOModel().Mapping.ElementId);
323322
if (entityDetails.ProjectedType == returnDto)
324323
{
325-
statements.Add($"return {entityDetails.VariableName}.{mappingMethod}();");
324+
statements.Add(new CSharpReturnStatement($"{entityDetails.VariableName}.{mappingMethod}()"));
326325
}
327326
else
328327
{
329328

330329
var mapper = MappingStrategyProvider.Instance.GetMappingStrategy(method)!;
331330
mapper.ImplementPagedMappingStatement(method, statements, entityDetails, template, returnType, returnDto, mappingMethod);
332-
//statements.Add($"return {entityDetails.VariableName}.{mappingMethod}(x => x.MapTo{returnDto}({autoMapperFieldName}));");
333331
}
334332
}
335333
else if (returnType.Element.IsTypeDefinitionModel() && (nonUserSuppliedEntitiesReturningPks.Count == 1 || entitiesReturningPk.Count == 1)) // No need for TrackedEntities thus no check for it
@@ -338,12 +336,12 @@ public static IEnumerable<CSharpStatement> GetReturnStatements(this CSharpClassM
338336
? nonUserSuppliedEntitiesReturningPks[0]
339337
: entitiesReturningPk[0];
340338
var entity = entityDetails.ElementModel.AsClassModel();
341-
statements.Add($"return {entityDetails.VariableName}.{entity.GetTypesInHierarchy().SelectMany(x => x.Attributes).FirstOrDefault(x => x.IsPrimaryKey(isUserSupplied: false))?.Name ?? "Id"};");
339+
statements.Add(new CSharpReturnStatement($"{entityDetails.VariableName}.{entity.GetTypesInHierarchy().SelectMany(x => x.Attributes).FirstOrDefault(x => x.IsPrimaryKey(isUserSupplied: false))?.Name ?? "Id"}"));
342340
}
343341
else if (method.TrackedEntities().Values.Any(x => returnType.Element.Id == x.ElementModel.Id))
344342
{
345343
var entityDetails = method.TrackedEntities().Values.First(x => returnType.Element.Id == x.ElementModel.Id);
346-
statements.Add($"return {entityDetails.VariableName};");
344+
statements.Add(new CSharpReturnStatement(entityDetails.VariableName));
347345
}
348346
else
349347
{

Modules/Intent.Modules.Application.DomainInteractions/Intent.Application.DomainInteractions.imodspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<package>
33
<id>Intent.Application.DomainInteractions</id>
4-
<version>1.1.6</version>
4+
<version>1.1.7-pre.2</version>
55
<supportedClientVersions>[4.5.15-a,5.0.0)</supportedClientVersions>
66
<summary>Provides interaction strategies to generate domain interaction implementations.</summary>
77
<description>Provides interaction strategies to generate domain interaction implementations.</description>

Modules/Intent.Modules.Application.DomainInteractions/Intent.Metadata/Module Builder/Intent.Application.DomainInteractions/Intent.Application.DomainInteractions.pkg.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<definitionPackageName>Intent.ModuleBuilder</definitionPackageName>
3434
<definitionPackageId>9972b2a9-b749-4bba-b5c8-824bf694c6ef</definitionPackageId>
3535
<properties>
36-
<property name="4bb9695b-6004-46e1-acea-c48c60c5f8ce" display="Version" value="1.1.6" isActive="true" />
36+
<property name="4bb9695b-6004-46e1-acea-c48c60c5f8ce" display="Version" value="1.1.7-pre.1" isActive="true" />
3737
<property name="177a2415-e749-46e7-8257-440e19ecfb5e" display="API Namespace" value="Intent.Modules.Application.Contracts.Api" isActive="true" />
3838
<property name="0d2ae582-090e-42d6-a7d6-689144433254" display="NuGet Package Id" isActive="true" />
3939
<property name="27cf6544-a9a2-4992-9fef-51d0ed49e66e" display="NuGet Package Version" value="" isActive="true" />

Modules/Intent.Modules.Application.DomainInteractions/Intent.Modules.Application.DomainInteractions.application.output.config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<outputFiles>
33
<files>
44
<file relativePath="Intent.Modules.Application.DomainInteractions/Intent.Modules.Application.DomainInteractions.csproj" state="ignored" />
5-
<file relativePath="Intent.Modules.Application.DomainInteractions/release-notes.md" state="once-off-generated" />
5+
<file relativePath="Intent.Modules.Application.DomainInteractions/release-notes.md" state="ignored;once-off-generated" />
66
</files>
77
</outputFiles>

Modules/Intent.Modules.Application.DomainInteractions/Intent.Modules.Application.DomainInteractions.application.output.log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<OverwriteBehaviour>once-off</OverwriteBehaviour>
3939
<ApplicationRelativeFilePath>release-notes.md</ApplicationRelativeFilePath>
4040
<ProjectRelativeFilePath>release-notes.md</ProjectRelativeFilePath>
41-
<IsIgnored>false</IsIgnored>
41+
<IsIgnored>true</IsIgnored>
4242
</FileLog>
4343
</FileLogs>
4444
</outputLog>

Modules/Intent.Modules.Application.DomainInteractions/Intent.Modules.Application.DomainInteractions.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework>net8.0</TargetFramework>
5-
<Version>1.1.6</Version>
5+
<Version>1.1.7-pre.2</Version>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

Modules/Intent.Modules.Application.DomainInteractions/InteractionStrategies/CreateEntityInteractionStrategy.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private static void AddSaveChangesStatements(ICSharpClassMethodDeclaration metho
9898
if (entity.ElementModel.IsClassModel())
9999
{
100100
var primaryKeys = entity.ElementModel.AsClassModel().GetTypesInHierarchy().SelectMany(c => c.Attributes.Where(a => a.IsPrimaryKey()));
101-
if (primaryKeys.Any(HasDBGeneratedPk))
101+
if (primaryKeys.Any(p => HasDBGeneratedPk(entity.ElementModel, p)))
102102
{
103103
method.AddStatement(ExecutionPhases.Persistence, new CSharpStatement($"{entity.DataAccessProvider.SaveChangesAsync()}"));
104104
}
@@ -137,9 +137,34 @@ private static List<EntityDetails> GetEntitiesReturningPk(ICSharpClassMethodDecl
137137
.ToList();
138138
}
139139

140-
private static bool HasDBGeneratedPk(AttributeModel attribute)
140+
private class DataSources
141141
{
142-
return attribute.IsPrimaryKey() && attribute.GetStereotypeProperty("Primary Key", "Data source", "Default") == "Default";
142+
/// <summary>
143+
/// Explicitly Stating the Keys are Auto-generated
144+
/// DB Tech may have options for how ths is done, e.g. EF has options here
145+
/// For EF this typically means assigned on Save Changes
146+
/// For Cosmos this would typically be set on object construction
147+
/// </summary>
148+
public const string AutoGenerated = "Auto-generated";
149+
/// <summary>
150+
/// What ever the default is for the technology.
151+
/// e.g. EF Auto-generated PKs, Guids EF assigned in Memory, Oridinals are DB Assigned
152+
/// </summary>
153+
public const string Default = "Default";
154+
/// <summary>
155+
/// PKS are set but the explicitly (Business keys, composite keys, these are typcially not auto assigned)
156+
/// </summary>
157+
public const string UserSupplied = "User supplied";
158+
}
159+
160+
private static bool HasDBGeneratedPk(IElement entity, AttributeModel attribute)
161+
{
162+
if (entity.Package.AsDomainPackageModel()?.HasStereotype("Relational Database") == true)
163+
{
164+
return attribute.IsPrimaryKey() && attribute.GetStereotypeProperty("Primary Key", "Data source", "Default") is DataSources.Default or DataSources.AutoGenerated;
165+
}
166+
// For document DBs User Supplied and Auto-generated is assumed to not be set by the DB
167+
return attribute.IsPrimaryKey() && attribute.GetStereotypeProperty("Primary Key", "Data source", "Default") == DataSources.Default;
143168
}
144169
}
145170
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using Intent.Metadata.Models;
4+
using Intent.Modules.Common.CSharp.Builder;
5+
using Intent.Modules.Common.CSharp.Interactions;
6+
using Intent.Modules.Common.CSharp.Templates;
7+
8+
namespace Intent.Modules.Application.DomainInteractions.Strategies;
9+
10+
internal class AutoMapperMappingStrategy : IMappingStrategy
11+
{
12+
public bool IsMatch(ICSharpClassMethodDeclaration method)
13+
{
14+
return method.File.Template.ExecutionContext.InstalledModules.Any(x => x.ModuleId == "Intent.Application.Dtos.AutoMapper");
15+
}
16+
17+
public void ImplementMappingStatement(ICSharpClassMethodDeclaration method, List<CSharpStatement> statements,
18+
EntityDetails entity, ICSharpTemplate template, ITypeReference returnType, string? returnDto)
19+
{
20+
//Adding Using Clause for Extension Methods
21+
template.TryGetTypeName("Intent.Application.Dtos.EntityDtoMappingExtensions", returnType.Element, out _);
22+
var autoMapperFieldName = method.Class.InjectService(template.UseType("AutoMapper.IMapper"));
23+
var nullable = returnType.IsNullable ? "?" : "";
24+
statements.Add($"return {entity.VariableName}{nullable}.MapTo{returnDto}{(returnType.IsCollection ? "List" : "")}({autoMapperFieldName});");
25+
}
26+
27+
public void ImplementPagedMappingStatement(ICSharpClassMethodDeclaration method, List<CSharpStatement> statements, EntityDetails entity,
28+
ICSharpTemplate template, ITypeReference returnType, string? returnDto, string? mappingMethod)
29+
{
30+
var autoMapperFieldName = method.Class.InjectService(template.UseType("AutoMapper.IMapper"));
31+
statements.Add($"return {entity.VariableName}.{mappingMethod}(x => x.MapTo{returnDto}({autoMapperFieldName}));");
32+
}
33+
34+
public bool HasProjectTo() => true;
35+
}

Modules/Intent.Modules.Application.DomainInteractions/Strategies/IMappingStrategy.cs

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
using Intent.Modules.Common.CSharp.Builder;
33
using Intent.Modules.Common.CSharp.Interactions;
44
using Intent.Modules.Common.CSharp.Templates;
5-
using System;
65
using System.Collections.Generic;
7-
using System.Linq;
86
using System.Text;
97
using System.Threading.Tasks;
108

@@ -21,60 +19,4 @@ void ImplementMappingStatement(ICSharpClassMethodDeclaration method, List<CSharp
2119
void ImplementPagedMappingStatement(ICSharpClassMethodDeclaration method, List<CSharpStatement> statements, EntityDetails entity, ICSharpTemplate template,
2220
ITypeReference returnType, string? returnDto, string? mappingMethod);
2321
}
24-
25-
public class AutoMapperMappingStrategy : IMappingStrategy
26-
{
27-
public bool IsMatch(ICSharpClassMethodDeclaration method)
28-
{
29-
return method.File.Template.ExecutionContext.InstalledModules.Any(x => x.ModuleId == "Intent.Application.Dtos.AutoMapper");
30-
}
31-
32-
public void ImplementMappingStatement(ICSharpClassMethodDeclaration method, List<CSharpStatement> statements,
33-
EntityDetails entity, ICSharpTemplate template, ITypeReference returnType, string? returnDto)
34-
{
35-
//Adding Using Clause for Extension Methods
36-
template.TryGetTypeName("Intent.Application.Dtos.EntityDtoMappingExtensions", returnType.Element, out _);
37-
var autoMapperFieldName = method.Class.InjectService(template.UseType("AutoMapper.IMapper"));
38-
var nullable = returnType.IsNullable ? "?" : "";
39-
statements.Add($"return {entity.VariableName}{nullable}.MapTo{returnDto}{(returnType.IsCollection ? "List" : "")}({autoMapperFieldName});");
40-
}
41-
42-
public void ImplementPagedMappingStatement(ICSharpClassMethodDeclaration method, List<CSharpStatement> statements, EntityDetails entity,
43-
ICSharpTemplate template, ITypeReference returnType, string? returnDto, string? mappingMethod)
44-
{
45-
var autoMapperFieldName = method.Class.InjectService(template.UseType("AutoMapper.IMapper"));
46-
statements.Add($"return {entity.VariableName}.{mappingMethod}(x => x.MapTo{returnDto}({autoMapperFieldName}));");
47-
}
48-
49-
public bool HasProjectTo() => true;
50-
}
51-
52-
public class MapperlyMappingStrategy : IMappingStrategy
53-
{
54-
public bool IsMatch(ICSharpClassMethodDeclaration method)
55-
{
56-
return method.File.Template.ExecutionContext.InstalledModules.Any(x => x.ModuleId == "Intent.Application.Dtos.Mapperly");
57-
}
58-
59-
public void ImplementMappingStatement(ICSharpClassMethodDeclaration method, List<CSharpStatement> statements,
60-
EntityDetails entity, ICSharpTemplate template, ITypeReference returnType, string? returnDto)
61-
{
62-
var nullable = returnType.IsNullable ? "?" : "";
63-
template.TryGetTypeName("Intent.Application.Dtos.Mapperly.DtoMappingProfile", returnType.Element, out var _);
64-
statements.Add($"var mapper = new {entity.ElementModel.Name}DtoMapper();");
65-
statements.Add($"return mapper.{entity.ElementModel.Name}To{returnDto}{(returnType.IsCollection ? "List" : "")}({entity.VariableName}{(returnType.IsCollection ? ".ToList()" : "")});");
66-
}
67-
68-
public void ImplementPagedMappingStatement(ICSharpClassMethodDeclaration method, List<CSharpStatement> statements, EntityDetails entity,
69-
ICSharpTemplate template, ITypeReference returnType, string? returnDto, string? mappingMethod)
70-
{
71-
template.TryGetTypeName("Intent.Application.Dtos.Mapperly.DtoMappingProfile", returnType.Element, out var _);
72-
statements.Add($"var mapper = new {entity.ElementModel.Name}DtoMapper();");
73-
statements.Add($"return {entity.VariableName}.{mappingMethod}(x => mapper.{entity.ElementModel.Name}To{returnDto}(x));");
74-
return;
75-
throw new NotImplementedException();
76-
}
77-
78-
public bool HasProjectTo() => false;
79-
}
8022
}

0 commit comments

Comments
 (0)