Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port Fix repository validation that failes for inverted type list to MORYX 8 #442

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.0.5
8.0.6
12 changes: 4 additions & 8 deletions src/Moryx.Model/Repositories/Proxy/RepositoryProxyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static RepositoryProxyBuilder()
public Type Build(Type repoApi)
{
// Check interface
ValidateRepositoryApi(repoApi, false);
ValidateRepositoryApi(repoApi);

var proxyName = CreateProxyName(repoApi);

Expand Down Expand Up @@ -86,7 +86,7 @@ public Type Build(Type repoApi)
public Type Build(Type repoApi, Type repoImpl)
{
// Check interface
ValidateRepositoryApi(repoApi, false);
ValidateRepositoryApi(repoApi);

var proxyName = CreateProxyName(repoImpl);

Expand Down Expand Up @@ -198,19 +198,15 @@ private static bool IsModificationTracked(Type entityType)
return typeof(IModificationTrackedEntity).IsAssignableFrom(entityType);
}

private static void ValidateRepositoryApi(Type repoApi, bool additionalApis)
private static void ValidateRepositoryApi(Type repoApi)
{
if (!repoApi.IsInterface)
{
throw new InvalidOperationException($"'{repoApi.Name}' is not an interface");
}

var repoInterfaces = repoApi.GetInterfaces();
if (additionalApis && (repoInterfaces.Length > 2 || repoInterfaces.First().GetGenericTypeDefinition() != typeof(IRepository<>)))
{
throw new InvalidOperationException($"'{repoApi.Name}' API does not inherit from IRepository<T>");
}
else if (repoInterfaces.Length != 2 || repoInterfaces.First().GetGenericTypeDefinition() != typeof(IRepository<>))
if (!repoInterfaces.Any(rI => rI.IsGenericType && rI.GetGenericTypeDefinition() == typeof(IRepository<>)))
{
throw new InvalidOperationException($"'{repoApi.Name}' API does not inherit from IRepository<T>");
}
Expand Down
Loading