Skip to content

Commit

Permalink
0.0.57-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérôme PACELLI committed Oct 14, 2024
1 parent cfdc4b6 commit 3463977
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<LangVersion>9</LangVersion>
<CheckEolTargetFramework>false</CheckEolTargetFramework>

<Version>0.0.56-alpha</Version>
<Version>0.0.57-alpha</Version>
<PackageLicenseExpression>MIT</PackageLicenseExpression>

<PackageProjectUrl>https://github.com/jpacelli62/Faaast</PackageProjectUrl>
Expand Down
11 changes: 10 additions & 1 deletion src/Faaast.Metadata/ApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Faaast.Metadata;
using System.Collections.Generic;
using System;
using Faaast.Metadata;
using Microsoft.Extensions.DependencyInjection.Extensions;

namespace Microsoft.Extensions.DependencyInjection
Expand All @@ -10,5 +12,12 @@ public static IServiceCollection AddMetadata(this IServiceCollection services)
services.TryAddSingleton<IObjectMapper, DefaultObjectMapper>();
return services;
}

public static IServiceCollection AddMetadata(this IServiceCollection services, Dictionary<Type, IDtoClass> definitions)
{
var mapper = new DefaultObjectMapper(definitions);
services.TryAddSingleton<IObjectMapper>(mapper);
return services;
}
}
}
4 changes: 4 additions & 0 deletions src/Faaast.Metadata/DefaultObjectMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public class DefaultObjectMapper : IObjectMapper
{
private Dictionary<Type, IDtoClass> Definitions { get; } = new Dictionary<Type, IDtoClass>();

public DefaultObjectMapper() { }

public DefaultObjectMapper(Dictionary<Type, IDtoClass> definitions) => this.Definitions = definitions;

private readonly ReadWriteSync _sync = new();

public IDtoClass Get(Type type)
Expand Down
49 changes: 28 additions & 21 deletions src/Faaast.SeoRouter/RoutingRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public virtual RouteValueDictionary UrlTokens()

public virtual VirtualPathData GetVirtualPath(IRouter router, RouteValueDictionary ambiantValues, RouteValueDictionary values)
{
var pathData = new VirtualPathData(router, this.Url);
if (this.Kind == RuleKind.Global)
{
foreach (var parameter in _routeTemplate.Parameters)
Expand All @@ -230,38 +231,44 @@ public virtual VirtualPathData GetVirtualPath(IRouter router, RouteValueDictiona
}
}

var binderValues = _binder.GetValues(ambiantValues, values);
if (binderValues == null)
string virtualPath;
if (this.IsDynamic)
{
// We're missing one of the required values for this route.
return null;
}

var virtualPath = _binder.BindValues(binderValues.AcceptedValues);
if (virtualPath == null)
{
return null;
}
var binderValues = _binder.GetValues(ambiantValues, values);
if (binderValues == null)
{
// We're missing one of the required values for this route.
return null;
}

if (this.Url.EndsWith("/") && !virtualPath.EndsWith("/"))
{
virtualPath += "/";
}
virtualPath = _binder.BindValues(binderValues.AcceptedValues);
if (virtualPath == null)
{
return null;
}
if (this.Url.EndsWith("/") && !virtualPath.EndsWith("/"))
{
virtualPath += "/";
}

var pathData = new VirtualPathData(router, virtualPath);
foreach (var dataToken in binderValues.CombinedValues)
{
if (!binderValues.AcceptedValues.ContainsKey(dataToken.Key))
pathData = new VirtualPathData(router, virtualPath);
foreach (var dataToken in binderValues.CombinedValues)
{
pathData.DataTokens.Add(dataToken.Key, dataToken.Value);
if (!binderValues.AcceptedValues.ContainsKey(dataToken.Key))
{
pathData.DataTokens.Add(dataToken.Key, dataToken.Value);
}
}
}
else
{
return pathData;
}

return pathData;
}
else
{
var pathData = new VirtualPathData(router, this.Url);
return pathData;
}
}
Expand Down

0 comments on commit 3463977

Please sign in to comment.