Skip to content

Commit 5d30939

Browse files
committed
Improved error message when ProjectTo is selected as the query strategy with an unsupporting provider (mapperly)
1 parent ffb8153 commit 5d30939

File tree

5 files changed

+20
-5
lines changed

5 files changed

+20
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<package>
33
<id>Intent.Application.DomainInteractions</id>
4-
<version>1.1.5</version>
4+
<version>1.1.6-pre.0</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.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.5</Version>
5+
<Version>1.1.6-pre.0</Version>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<Nullable>enable</Nullable>
88
</PropertyGroup>

Modules/Intent.Modules.Application.DomainInteractions/QueryActionContext.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
using System;
2-
using System.Linq;
3-
using Intent.Exceptions;
1+
using Intent.Exceptions;
42
using Intent.Metadata.Models;
53
using Intent.Modelers.Domain.Api;
64
using Intent.Modelers.Services.Api;
5+
using Intent.Modules.Application.DomainInteractions.Strategies;
76
using Intent.Modules.Common.CSharp.Builder;
87
using Intent.Modules.Common.CSharp.Templates;
8+
using System;
9+
using System.Linq;
910
using OperationModelExtensions = Intent.Modelers.Domain.Api.OperationModelExtensions;
1011

1112
namespace Intent.Modules.Application.DomainInteractions
@@ -34,6 +35,11 @@ public QueryActionContext(ICSharpClassMethodDeclaration method, ActionType actio
3435
IsPaginated = true;
3536
ReturnType = _serviceEndPoint.TypeReference!.GenericTypeParameters.FirstOrDefault()?.Element as IElement;
3637
}
38+
var mapper = MappingStrategyProvider.Instance.GetMappingStrategy(method);
39+
if (!mapper?.HasProjectTo() ?? true)
40+
{
41+
throw new ElementException(AssociationEnd, "'ProjectTo' functionality is unavailable with the current mapping provider. Use a supporting module (e.g., Intent.Application.AutoMapper), or change the application setting \"Default Query Implementation\" from 'ProjectTo' to 'Default'.");
42+
}
3743
if (IsConfiguredForProjections())
3844
{
3945
//We're doing this because the CRUD modules are generally compatible with AutoMapper module v4 this Feature requires V5.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace Intent.Modules.Application.DomainInteractions.Strategies
1212
{
1313
public interface IMappingStrategy
1414
{
15+
bool HasProjectTo();
1516
bool IsMatch(ICSharpClassMethodDeclaration method);
1617

1718
void ImplementMappingStatement(ICSharpClassMethodDeclaration method, List<CSharpStatement> statements,
@@ -44,6 +45,8 @@ public void ImplementPagedMappingStatement(ICSharpClassMethodDeclaration method,
4445
var autoMapperFieldName = method.Class.InjectService(template.UseType("AutoMapper.IMapper"));
4546
statements.Add($"return {entity.VariableName}.{mappingMethod}(x => x.MapTo{returnDto}({autoMapperFieldName}));");
4647
}
48+
49+
public bool HasProjectTo() => true;
4750
}
4851

4952
public class MapperlyMappingStrategy : IMappingStrategy
@@ -71,5 +74,7 @@ public void ImplementPagedMappingStatement(ICSharpClassMethodDeclaration method,
7174
return;
7275
throw new NotImplementedException();
7376
}
77+
78+
public bool HasProjectTo() => false;
7479
}
7580
}

Modules/Intent.Modules.Application.DomainInteractions/release-notes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
### Version 1.1.6
2+
3+
- Improvement: Improved error message when `ProjectTo` is selected as the query strategy with an unsupporting provider (mapperly)
4+
15
### Version 1.1.5
26

37
- Improvement: Support for Mapperly module

0 commit comments

Comments
 (0)