diff --git a/src/BitzArt.Flux.Json/BitzArt.Flux.Json.csproj b/src/BitzArt.Flux.Json/BitzArt.Flux.Json.csproj
index c0c1e91..e28ec79 100644
--- a/src/BitzArt.Flux.Json/BitzArt.Flux.Json.csproj
+++ b/src/BitzArt.Flux.Json/BitzArt.Flux.Json.csproj
@@ -12,7 +12,7 @@
MIT
git
https://github.com/BitzArt/Flux
- https://github.com/BitzArt/Flux
+ https://bitzart.github.io/Flux
README.md
flux-logo-128.png
diff --git a/src/BitzArt.Flux.Json/Exceptions/FluxItemNotFoundException.cs b/src/BitzArt.Flux.Json/Exceptions/FluxItemNotFoundException.cs
new file mode 100644
index 0000000..bf0eb23
--- /dev/null
+++ b/src/BitzArt.Flux.Json/Exceptions/FluxItemNotFoundException.cs
@@ -0,0 +1,7 @@
+namespace BitzArt.Flux;
+
+internal class FluxItemNotFoundException : Exception
+{
+ public FluxItemNotFoundException(object? id) : base($"{typeof(TModel).Name} with key {id} was not found")
+ { }
+}
\ No newline at end of file
diff --git a/src/BitzArt.Flux.Json/Builder/Exceptions/FluxJsonDeserializationException.cs b/src/BitzArt.Flux.Json/Exceptions/FluxJsonDeserializationException.cs
similarity index 100%
rename from src/BitzArt.Flux.Json/Builder/Exceptions/FluxJsonDeserializationException.cs
rename to src/BitzArt.Flux.Json/Exceptions/FluxJsonDeserializationException.cs
diff --git a/src/BitzArt.Flux.Json/Builder/Exceptions/FluxJsonFileReadException.cs b/src/BitzArt.Flux.Json/Exceptions/FluxJsonFileReadException.cs
similarity index 100%
rename from src/BitzArt.Flux.Json/Builder/Exceptions/FluxJsonFileReadException.cs
rename to src/BitzArt.Flux.Json/Exceptions/FluxJsonFileReadException.cs
diff --git a/src/BitzArt.Flux.Json/Exceptions/FluxJsonMissingDataException.cs b/src/BitzArt.Flux.Json/Exceptions/FluxJsonMissingDataException.cs
new file mode 100644
index 0000000..ea50396
--- /dev/null
+++ b/src/BitzArt.Flux.Json/Exceptions/FluxJsonMissingDataException.cs
@@ -0,0 +1,7 @@
+namespace BitzArt.Flux;
+
+internal class FluxJsonMissingDataException : Exception
+{
+ public FluxJsonMissingDataException() : base("Missing set data. Consider populating the set with json data when configuring Flux.")
+ { }
+}
diff --git a/src/BitzArt.Flux.Json/Exceptions/FluxKeyPropertyExpressionMissingException.cs b/src/BitzArt.Flux.Json/Exceptions/FluxKeyPropertyExpressionMissingException.cs
new file mode 100644
index 0000000..b86b6a7
--- /dev/null
+++ b/src/BitzArt.Flux.Json/Exceptions/FluxKeyPropertyExpressionMissingException.cs
@@ -0,0 +1,8 @@
+namespace BitzArt.Flux;
+
+internal class FluxKeyPropertyExpressionMissingException : Exception
+{
+ public FluxKeyPropertyExpressionMissingException() : base($"KeyPropertyExpression is required for {typeof(TModel).Name}. Consider using .WithKey() when configuring a Set.")
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/BitzArt.Flux.Json/Builder/Extensions/AddSetExtension.cs b/src/BitzArt.Flux.Json/Extensions/AddSetExtension.cs
similarity index 100%
rename from src/BitzArt.Flux.Json/Builder/Extensions/AddSetExtension.cs
rename to src/BitzArt.Flux.Json/Extensions/AddSetExtension.cs
diff --git a/src/BitzArt.Flux.Json/Builder/Extensions/ConfigureJsonExtension.cs b/src/BitzArt.Flux.Json/Extensions/ConfigureJsonExtension.cs
similarity index 100%
rename from src/BitzArt.Flux.Json/Builder/Extensions/ConfigureJsonExtension.cs
rename to src/BitzArt.Flux.Json/Extensions/ConfigureJsonExtension.cs
diff --git a/src/BitzArt.Flux.Json/Builder/Extensions/FromJsonExtension.cs b/src/BitzArt.Flux.Json/Extensions/FromJsonExtension.cs
similarity index 100%
rename from src/BitzArt.Flux.Json/Builder/Extensions/FromJsonExtension.cs
rename to src/BitzArt.Flux.Json/Extensions/FromJsonExtension.cs
diff --git a/src/BitzArt.Flux.Json/Builder/Extensions/FromJsonFileExtension.cs b/src/BitzArt.Flux.Json/Extensions/FromJsonFileExtension.cs
similarity index 100%
rename from src/BitzArt.Flux.Json/Builder/Extensions/FromJsonFileExtension.cs
rename to src/BitzArt.Flux.Json/Extensions/FromJsonFileExtension.cs
diff --git a/src/BitzArt.Flux.Json/Builder/Extensions/UsingJsonExtension.cs b/src/BitzArt.Flux.Json/Extensions/UsingJsonExtension.cs
similarity index 100%
rename from src/BitzArt.Flux.Json/Builder/Extensions/UsingJsonExtension.cs
rename to src/BitzArt.Flux.Json/Extensions/UsingJsonExtension.cs
diff --git a/src/BitzArt.Flux.Json/Builder/Extensions/WithBaseFilePathExtension.cs b/src/BitzArt.Flux.Json/Extensions/WithBaseFilePathExtension.cs
similarity index 100%
rename from src/BitzArt.Flux.Json/Builder/Extensions/WithBaseFilePathExtension.cs
rename to src/BitzArt.Flux.Json/Extensions/WithBaseFilePathExtension.cs
diff --git a/src/BitzArt.Flux.Json/Builder/Extensions/WithKeyExtension.cs b/src/BitzArt.Flux.Json/Extensions/WithKeyExtension.cs
similarity index 100%
rename from src/BitzArt.Flux.Json/Builder/Extensions/WithKeyExtension.cs
rename to src/BitzArt.Flux.Json/Extensions/WithKeyExtension.cs
diff --git a/src/BitzArt.Flux.Json/Builder/Interfaces/IFluxJsonServiceBuilder.cs b/src/BitzArt.Flux.Json/Interfaces/IFluxJsonServiceBuilder.cs
similarity index 100%
rename from src/BitzArt.Flux.Json/Builder/Interfaces/IFluxJsonServiceBuilder.cs
rename to src/BitzArt.Flux.Json/Interfaces/IFluxJsonServiceBuilder.cs
diff --git a/src/BitzArt.Flux.Json/Builder/Interfaces/IFluxJsonSetBuilder.cs b/src/BitzArt.Flux.Json/Interfaces/IFluxJsonSetBuilder.cs
similarity index 76%
rename from src/BitzArt.Flux.Json/Builder/Interfaces/IFluxJsonSetBuilder.cs
rename to src/BitzArt.Flux.Json/Interfaces/IFluxJsonSetBuilder.cs
index 7f569d1..8c9d962 100644
--- a/src/BitzArt.Flux.Json/Builder/Interfaces/IFluxJsonSetBuilder.cs
+++ b/src/BitzArt.Flux.Json/Interfaces/IFluxJsonSetBuilder.cs
@@ -1,6 +1,6 @@
namespace BitzArt.Flux;
-public interface IFluxJsonSetBuilder : IFluxModelBuilder, IFluxJsonServiceBuilder
+public interface IFluxJsonSetBuilder : IFluxJsonServiceBuilder
where TModel : class
{
public FluxJsonSetOptions SetOptions { get; }
diff --git a/src/BitzArt.Flux.Json/Builder/Models/FluxJsonServiceBuilder.cs b/src/BitzArt.Flux.Json/Models/FluxJsonServiceBuilder.cs
similarity index 100%
rename from src/BitzArt.Flux.Json/Builder/Models/FluxJsonServiceBuilder.cs
rename to src/BitzArt.Flux.Json/Models/FluxJsonServiceBuilder.cs
diff --git a/src/BitzArt.Flux.Json/Factory/Models/FluxJsonServiceFactory.cs b/src/BitzArt.Flux.Json/Models/FluxJsonServiceFactory.cs
similarity index 91%
rename from src/BitzArt.Flux.Json/Factory/Models/FluxJsonServiceFactory.cs
rename to src/BitzArt.Flux.Json/Models/FluxJsonServiceFactory.cs
index 1d1a6a8..7a2333f 100644
--- a/src/BitzArt.Flux.Json/Factory/Models/FluxJsonServiceFactory.cs
+++ b/src/BitzArt.Flux.Json/Models/FluxJsonServiceFactory.cs
@@ -125,15 +125,3 @@ public IFluxSetContext CreateSetContext(IServiceProv
return new FluxJsonSetContext(_serviceOptions, logger, options);
}
}
-
-internal class SetConfigurationNotFoundException : Exception
-{
- public SetConfigurationNotFoundException() : base("Requested Set Configuration was not found.")
- { }
-}
-
-internal class SetAlreadyRegisteredException : Exception
-{
- public SetAlreadyRegisteredException(string name) : base($"An unnamed Flux Set for a model '{name}' was already registered previously. Consider giving specific names to different sets for this model.")
- { }
-}
\ No newline at end of file
diff --git a/src/BitzArt.Flux.Json/Builder/Models/FluxJsonSetBuilder.cs b/src/BitzArt.Flux.Json/Models/FluxJsonSetBuilder.cs
similarity index 100%
rename from src/BitzArt.Flux.Json/Builder/Models/FluxJsonSetBuilder.cs
rename to src/BitzArt.Flux.Json/Models/FluxJsonSetBuilder.cs
diff --git a/src/BitzArt.Flux.Json/Models/FluxJsonSetContext{TModel,TKey}.cs b/src/BitzArt.Flux.Json/Models/FluxJsonSetContext{TModel,TKey}.cs
new file mode 100644
index 0000000..5865e66
--- /dev/null
+++ b/src/BitzArt.Flux.Json/Models/FluxJsonSetContext{TModel,TKey}.cs
@@ -0,0 +1,42 @@
+using Microsoft.Extensions.Logging;
+
+namespace BitzArt.Flux;
+
+internal class FluxJsonSetContext : FluxJsonSetContext, IFluxSetContext
+ where TModel : class
+{
+ // ================ Flux internal wiring ================
+
+ internal new FluxJsonSetOptions SetOptions
+ {
+ get => (FluxJsonSetOptions)_setOptions;
+ set => _setOptions = value;
+ }
+
+ // ==================== Constructor ====================
+
+ public FluxJsonSetContext(FluxJsonServiceOptions serviceOptions, ILogger logger, FluxJsonSetOptions setOptions)
+ : base(serviceOptions, logger, setOptions)
+ {
+ SetOptions = setOptions;
+ }
+
+ // ============== Methods implementation ==============
+
+ public override Task GetAsync(object? id, params object[]? parameters) => GetAsync((TKey?)id, parameters);
+
+ public Task GetAsync(TKey? id, params object[]? parameters)
+ {
+ _logger.LogInformation("Get {type}[{id}]", typeof(TModel).Name, id is not null ? id.ToString() : "_");
+
+ var existingItem = SetOptions.Items!.FirstOrDefault(item =>
+ {
+ if (SetOptions.KeyPropertyExpression is null) throw new FluxKeyPropertyExpressionMissingException();
+
+ var itemId = SetOptions.KeyPropertyExpression.Compile().Invoke(item);
+ return Equals(itemId, id);
+ }) ?? throw new FluxItemNotFoundException(id);
+
+ return Task.FromResult(existingItem);
+ }
+}
\ No newline at end of file
diff --git a/src/BitzArt.Flux.Json/Context/Models/FluxJsonSetContext.cs b/src/BitzArt.Flux.Json/Models/FluxJsonSetContext{TModel}.cs
similarity index 54%
rename from src/BitzArt.Flux.Json/Context/Models/FluxJsonSetContext.cs
rename to src/BitzArt.Flux.Json/Models/FluxJsonSetContext{TModel}.cs
index 2ffb224..addb472 100644
--- a/src/BitzArt.Flux.Json/Context/Models/FluxJsonSetContext.cs
+++ b/src/BitzArt.Flux.Json/Models/FluxJsonSetContext{TModel}.cs
@@ -1,11 +1,15 @@
using BitzArt.Pagination;
using Microsoft.Extensions.Logging;
+using System.Collections;
+using System.Linq.Expressions;
namespace BitzArt.Flux;
-internal class FluxJsonSetContext : IFluxSetContext
+internal class FluxJsonSetContext : IFluxSetContext
where TModel : class
{
+ // ================ Flux internal wiring ================
+
internal readonly FluxJsonServiceOptions ServiceOptions;
internal readonly ILogger _logger;
@@ -16,13 +20,35 @@ internal virtual FluxJsonSetOptions SetOptions
set => _setOptions = value;
}
+ // ==================== Constructor ====================
+
public FluxJsonSetContext(FluxJsonServiceOptions serviceOptions, ILogger logger, FluxJsonSetOptions setOptions)
{
ServiceOptions = serviceOptions;
_logger = logger;
_setOptions = setOptions;
}
-
+
+ // ================ Linking parsed data ================
+
+ public ICollection Items => SetOptions.Items ?? throw new FluxJsonMissingDataException();
+ private IQueryable Query => Items.AsQueryable();
+
+ // ============== IEnumerable implementation ==============
+
+ public IEnumerator GetEnumerator() => Items.GetEnumerator();
+ IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
+
+ // ============== IQueryable implementation ==============
+
+ public Type ElementType => typeof(TModel);
+
+ public Expression Expression => Query.Expression;
+
+ public IQueryProvider Provider => Query.Provider;
+
+ // ============== Data methods implementation ==============
+
public virtual Task> GetAllAsync(params object[]? parameters)
{
_logger.LogInformation("GetAll {type}", typeof(TModel).Name);
@@ -57,49 +83,3 @@ public virtual Task GetAsync(object? id, params object[]? parameters)
return Task.FromResult(existingItem);
}
}
-
-internal class FluxJsonSetContext : FluxJsonSetContext, IFluxSetContext
- where TModel : class
-{
- internal new FluxJsonSetOptions SetOptions
- {
- get => (FluxJsonSetOptions)_setOptions;
- set => _setOptions = value;
- }
-
- public FluxJsonSetContext(FluxJsonServiceOptions serviceOptions, ILogger logger, FluxJsonSetOptions setOptions)
- : base(serviceOptions, logger, setOptions)
- {
- SetOptions = setOptions;
- }
-
- public override Task GetAsync(object? id, params object[]? parameters) => GetAsync((TKey?)id, parameters);
-
- public Task GetAsync(TKey? id, params object[]? parameters)
- {
- _logger.LogInformation("Get {type}[{id}]", typeof(TModel).Name, id is not null ? id.ToString() : "_");
-
- var existingItem = SetOptions.Items!.FirstOrDefault(item =>
- {
- if (SetOptions.KeyPropertyExpression is null) throw new FluxKeyPropertyExpressionMissingException();
-
- var itemId = SetOptions.KeyPropertyExpression.Compile().Invoke(item);
- return Equals(itemId, id);
- }) ?? throw new FluxItemNotFoundException(id);
-
- return Task.FromResult(existingItem);
- }
-}
-
-internal class FluxItemNotFoundException : Exception
-{
- public FluxItemNotFoundException(object? id) : base($"{typeof(TModel).Name} with key {id} was not found")
- { }
-}
-
-internal class FluxKeyPropertyExpressionMissingException : Exception
-{
- public FluxKeyPropertyExpressionMissingException() : base($"KeyPropertyExpression is required for {typeof(TModel).Name}. Consider using .WithKey() when configuring a Set.")
- {
- }
-}
\ No newline at end of file
diff --git a/src/BitzArt.Flux.Json/Context/Models/FluxJsonServiceOptions.cs b/src/BitzArt.Flux.Json/Options/FluxJsonServiceOptions.cs
similarity index 100%
rename from src/BitzArt.Flux.Json/Context/Models/FluxJsonServiceOptions.cs
rename to src/BitzArt.Flux.Json/Options/FluxJsonServiceOptions.cs
diff --git a/src/BitzArt.Flux.Json/Context/Models/FluxJsonSetOptions.cs b/src/BitzArt.Flux.Json/Options/FluxJsonSetOptions{TModel,TKey}.cs
similarity index 75%
rename from src/BitzArt.Flux.Json/Context/Models/FluxJsonSetOptions.cs
rename to src/BitzArt.Flux.Json/Options/FluxJsonSetOptions{TModel,TKey}.cs
index b6c32d1..c8286a7 100644
--- a/src/BitzArt.Flux.Json/Context/Models/FluxJsonSetOptions.cs
+++ b/src/BitzArt.Flux.Json/Options/FluxJsonSetOptions{TModel,TKey}.cs
@@ -1,20 +1,7 @@
-using System.Linq.Expressions;
+using System.Linq.Expressions;
namespace BitzArt.Flux;
-public class FluxJsonSetOptions
- where TModel : class
-{
- public ICollection? Items { get; set; }
- protected Expression>? _keyPropertyExpression;
-
- public Expression>? KeyPropertyExpression
- {
- get => _keyPropertyExpression;
- set => _keyPropertyExpression = value;
- }
-}
-
public class FluxJsonSetOptions : FluxJsonSetOptions
where TModel : class
{
diff --git a/src/BitzArt.Flux.Json/Options/FluxJsonSetOptions{TModel}.cs b/src/BitzArt.Flux.Json/Options/FluxJsonSetOptions{TModel}.cs
new file mode 100644
index 0000000..429fd01
--- /dev/null
+++ b/src/BitzArt.Flux.Json/Options/FluxJsonSetOptions{TModel}.cs
@@ -0,0 +1,17 @@
+using System.Linq.Expressions;
+
+namespace BitzArt.Flux;
+
+public class FluxJsonSetOptions
+ where TModel : class
+{
+ public ICollection? Items { get; set; }
+
+ protected Expression>? _keyPropertyExpression;
+
+ public Expression>? KeyPropertyExpression
+ {
+ get => _keyPropertyExpression;
+ set => _keyPropertyExpression = value;
+ }
+}
diff --git a/src/BitzArt.Flux.REST/BitzArt.Flux.REST.csproj b/src/BitzArt.Flux.REST/BitzArt.Flux.REST.csproj
index 1957975..99f4710 100644
--- a/src/BitzArt.Flux.REST/BitzArt.Flux.REST.csproj
+++ b/src/BitzArt.Flux.REST/BitzArt.Flux.REST.csproj
@@ -12,7 +12,7 @@
MIT
git
https://github.com/BitzArt/Flux
- https://github.com/BitzArt/Flux
+ https://bitzart.github.io/Flux
README.md
flux-logo-128.png
diff --git a/src/BitzArt.Flux.REST/Exceptions/FluxRestKeyNotFoundException.cs b/src/BitzArt.Flux.REST/Exceptions/FluxRestKeyNotFoundException.cs
new file mode 100644
index 0000000..c3f9b62
--- /dev/null
+++ b/src/BitzArt.Flux.REST/Exceptions/FluxRestKeyNotFoundException.cs
@@ -0,0 +1,7 @@
+namespace BitzArt.Flux;
+
+internal class FluxRestKeyNotFoundException : Exception
+{
+ private static readonly string Msg = $"Unable to find TKey for type '{typeof(TModel).Name}'. Consider specifying a key when registering the set.";
+ public FluxRestKeyNotFoundException() : base(Msg) { }
+}
diff --git a/src/BitzArt.Flux.REST/Builder/Extensions/AddSetExtension.cs b/src/BitzArt.Flux.REST/Extensions/AddSetExtension.cs
similarity index 100%
rename from src/BitzArt.Flux.REST/Builder/Extensions/AddSetExtension.cs
rename to src/BitzArt.Flux.REST/Extensions/AddSetExtension.cs
diff --git a/src/BitzArt.Flux.REST/Builder/Extensions/ConfigureHttpClientExtension.cs b/src/BitzArt.Flux.REST/Extensions/ConfigureHttpClientExtension.cs
similarity index 100%
rename from src/BitzArt.Flux.REST/Builder/Extensions/ConfigureHttpClientExtension.cs
rename to src/BitzArt.Flux.REST/Extensions/ConfigureHttpClientExtension.cs
diff --git a/src/BitzArt.Flux.REST/Builder/Extensions/ConfigureJsonExtension.cs b/src/BitzArt.Flux.REST/Extensions/ConfigureJsonExtension.cs
similarity index 100%
rename from src/BitzArt.Flux.REST/Builder/Extensions/ConfigureJsonExtension.cs
rename to src/BitzArt.Flux.REST/Extensions/ConfigureJsonExtension.cs
diff --git a/src/BitzArt.Flux.REST/Builder/Extensions/UsingRestExtension.cs b/src/BitzArt.Flux.REST/Extensions/UsingRestExtension.cs
similarity index 100%
rename from src/BitzArt.Flux.REST/Builder/Extensions/UsingRestExtension.cs
rename to src/BitzArt.Flux.REST/Extensions/UsingRestExtension.cs
diff --git a/src/BitzArt.Flux.REST/Builder/Extensions/WithEndpointExtension.cs b/src/BitzArt.Flux.REST/Extensions/WithEndpointExtension.cs
similarity index 100%
rename from src/BitzArt.Flux.REST/Builder/Extensions/WithEndpointExtension.cs
rename to src/BitzArt.Flux.REST/Extensions/WithEndpointExtension.cs
diff --git a/src/BitzArt.Flux.REST/Builder/Extensions/WithIdEndpointExtension.cs b/src/BitzArt.Flux.REST/Extensions/WithIdEndpointExtension.cs
similarity index 100%
rename from src/BitzArt.Flux.REST/Builder/Extensions/WithIdEndpointExtension.cs
rename to src/BitzArt.Flux.REST/Extensions/WithIdEndpointExtension.cs
diff --git a/src/BitzArt.Flux.REST/Builder/Extensions/WithPageEndpointExtension.cs b/src/BitzArt.Flux.REST/Extensions/WithPageEndpointExtension.cs
similarity index 100%
rename from src/BitzArt.Flux.REST/Builder/Extensions/WithPageEndpointExtension.cs
rename to src/BitzArt.Flux.REST/Extensions/WithPageEndpointExtension.cs
diff --git a/src/BitzArt.Flux.REST/Builder/Interfaces/IFluxRestServiceBuilder.cs b/src/BitzArt.Flux.REST/Interfaces/IFluxRestServiceBuilder.cs
similarity index 100%
rename from src/BitzArt.Flux.REST/Builder/Interfaces/IFluxRestServiceBuilder.cs
rename to src/BitzArt.Flux.REST/Interfaces/IFluxRestServiceBuilder.cs
diff --git a/src/BitzArt.Flux.REST/Builder/Interfaces/IFluxRestSetBuilder.cs b/src/BitzArt.Flux.REST/Interfaces/IFluxRestSetBuilder.cs
similarity index 76%
rename from src/BitzArt.Flux.REST/Builder/Interfaces/IFluxRestSetBuilder.cs
rename to src/BitzArt.Flux.REST/Interfaces/IFluxRestSetBuilder.cs
index b7a12a7..d9b3a2c 100644
--- a/src/BitzArt.Flux.REST/Builder/Interfaces/IFluxRestSetBuilder.cs
+++ b/src/BitzArt.Flux.REST/Interfaces/IFluxRestSetBuilder.cs
@@ -1,6 +1,6 @@
namespace BitzArt.Flux;
-public interface IFluxRestSetBuilder : IFluxModelBuilder, IFluxRestServiceBuilder
+public interface IFluxRestSetBuilder : IFluxRestServiceBuilder
where TModel : class
{
public FluxRestSetOptions SetOptions { get; }
diff --git a/src/BitzArt.Flux.REST/Builder/Models/FluxRestServiceBuilder.cs b/src/BitzArt.Flux.REST/Models/FluxRestServiceBuilder.cs
similarity index 100%
rename from src/BitzArt.Flux.REST/Builder/Models/FluxRestServiceBuilder.cs
rename to src/BitzArt.Flux.REST/Models/FluxRestServiceBuilder.cs
diff --git a/src/BitzArt.Flux.REST/Factory/Models/FluxRestServiceFactory.cs b/src/BitzArt.Flux.REST/Models/FluxRestServiceFactory.cs
similarity index 92%
rename from src/BitzArt.Flux.REST/Factory/Models/FluxRestServiceFactory.cs
rename to src/BitzArt.Flux.REST/Models/FluxRestServiceFactory.cs
index 276e3e8..bced1f0 100644
--- a/src/BitzArt.Flux.REST/Factory/Models/FluxRestServiceFactory.cs
+++ b/src/BitzArt.Flux.REST/Models/FluxRestServiceFactory.cs
@@ -127,15 +127,3 @@ public IFluxSetContext CreateSetContext(IServiceProv
return new FluxRestSetContext(httpClient, _serviceOptions, logger, options);
}
}
-
-internal class SetConfigurationNotFoundException : Exception
-{
- public SetConfigurationNotFoundException() : base("Requested Set Configuration was not found.")
- { }
-}
-
-internal class SetAlreadyRegisteredException : Exception
-{
- public SetAlreadyRegisteredException(string name) : base($"An unnamed Flux Set for a model '{name}' was already registered previously. Consider giving specific names to different sets for this model.")
- { }
-}
\ No newline at end of file
diff --git a/src/BitzArt.Flux.REST/Models/FluxRestSetBuilder{TModel, TKey}.cs b/src/BitzArt.Flux.REST/Models/FluxRestSetBuilder{TModel, TKey}.cs
new file mode 100644
index 0000000..9a39807
--- /dev/null
+++ b/src/BitzArt.Flux.REST/Models/FluxRestSetBuilder{TModel, TKey}.cs
@@ -0,0 +1,14 @@
+using Microsoft.Extensions.DependencyInjection;
+
+namespace BitzArt.Flux;
+
+internal class FluxRestSetBuilder : FluxRestSetBuilder, IFluxRestSetBuilder
+ where TModel : class
+{
+ public new FluxRestSetOptions SetOptions { get; set; }
+
+ public FluxRestSetBuilder(IFluxRestServiceBuilder serviceBuilder) : base(serviceBuilder)
+ {
+ SetOptions = new();
+ }
+}
diff --git a/src/BitzArt.Flux.REST/Builder/Models/FluxRestSetBuilder.cs b/src/BitzArt.Flux.REST/Models/FluxRestSetBuilder{TModel}.cs
similarity index 72%
rename from src/BitzArt.Flux.REST/Builder/Models/FluxRestSetBuilder.cs
rename to src/BitzArt.Flux.REST/Models/FluxRestSetBuilder{TModel}.cs
index e8406be..6c3b25b 100644
--- a/src/BitzArt.Flux.REST/Builder/Models/FluxRestSetBuilder.cs
+++ b/src/BitzArt.Flux.REST/Models/FluxRestSetBuilder{TModel}.cs
@@ -26,14 +26,3 @@ public FluxRestSetBuilder(IFluxRestServiceBuilder serviceBuilder)
SetOptions = new();
}
}
-
-internal class FluxRestSetBuilder : FluxRestSetBuilder, IFluxRestSetBuilder
- where TModel : class
-{
- public new FluxRestSetOptions SetOptions { get; set; }
-
- public FluxRestSetBuilder(IFluxRestServiceBuilder serviceBuilder) : base(serviceBuilder)
- {
- SetOptions = new();
- }
-}
diff --git a/src/BitzArt.Flux.REST/Models/FluxRestSetContext{TModel,TKey}.cs b/src/BitzArt.Flux.REST/Models/FluxRestSetContext{TModel,TKey}.cs
new file mode 100644
index 0000000..bc20307
--- /dev/null
+++ b/src/BitzArt.Flux.REST/Models/FluxRestSetContext{TModel,TKey}.cs
@@ -0,0 +1,51 @@
+using Microsoft.Extensions.Logging;
+
+namespace BitzArt.Flux;
+
+internal class FluxRestSetContext : FluxRestSetContext, IFluxSetContext
+ where TModel : class
+{
+ // ================ Flux internal wiring ================
+
+ internal new FluxRestSetOptions SetOptions
+ {
+ get => (FluxRestSetOptions)_setOptions;
+ set => _setOptions = value;
+ }
+
+ // ==================== Constructor ====================
+
+ public FluxRestSetContext(HttpClient httpClient, FluxRestServiceOptions serviceOptions, ILogger logger, FluxRestSetOptions setOptions)
+ : base(httpClient, serviceOptions, logger, setOptions)
+ {
+ SetOptions = setOptions;
+ }
+
+ // ============== Data methods implementation ==============
+
+ public override Task GetAsync(object? id, params object[]? parameters) => GetAsync((TKey?)id, parameters);
+
+ public async Task GetAsync(TKey? id, params object[]? parameters)
+ {
+ string idEndpoint;
+
+ bool handleParameters = false;
+ if (SetOptions.GetIdEndpointAction is not null)
+ {
+ idEndpoint = SetOptions.GetIdEndpointAction(id, parameters);
+ }
+ else
+ {
+ idEndpoint = SetOptions.Endpoint is not null ? Path.Combine(SetOptions.Endpoint, id!.ToString()!) : id!.ToString()!;
+ handleParameters = true;
+ }
+ var parse = GetFullPath(idEndpoint, handleParameters, parameters);
+
+ _logger.LogInformation("Get {type}[{id}]: {route}{parsingLog}", typeof(TModel).Name, id!.ToString(), parse.Result, parse.Log);
+
+ var message = new HttpRequestMessage(HttpMethod.Get, parse.Result);
+ var result = await HandleRequestAsync(message);
+
+ return result;
+ }
+}
diff --git a/src/BitzArt.Flux.REST/Context/Models/FluxRestSetContext.cs b/src/BitzArt.Flux.REST/Models/FluxRestSetContext{TModel}.cs
similarity index 70%
rename from src/BitzArt.Flux.REST/Context/Models/FluxRestSetContext.cs
rename to src/BitzArt.Flux.REST/Models/FluxRestSetContext{TModel}.cs
index 1f025bf..7e6d6e8 100644
--- a/src/BitzArt.Flux.REST/Context/Models/FluxRestSetContext.cs
+++ b/src/BitzArt.Flux.REST/Models/FluxRestSetContext{TModel}.cs
@@ -1,5 +1,7 @@
using BitzArt.Pagination;
using Microsoft.Extensions.Logging;
+using System.Collections;
+using System.Linq.Expressions;
using System.Text.Json;
using System.Web;
@@ -8,6 +10,8 @@ namespace BitzArt.Flux;
internal class FluxRestSetContext : IFluxSetContext
where TModel : class
{
+ // ================ Flux internal wiring ================
+
internal readonly HttpClient HttpClient;
internal readonly FluxRestServiceOptions ServiceOptions;
internal readonly ILogger _logger;
@@ -19,6 +23,29 @@ internal virtual FluxRestSetOptions SetOptions
set => _setOptions = value;
}
+ // ==================== Constructor ====================
+
+ public FluxRestSetContext(HttpClient httpClient, FluxRestServiceOptions serviceOptions, ILogger logger, FluxRestSetOptions setOptions)
+ {
+ HttpClient = httpClient;
+ ServiceOptions = serviceOptions;
+ _logger = logger;
+ _setOptions = setOptions;
+ }
+
+ // ============== IEnumerable implementation ==============
+
+ public IEnumerator GetEnumerator() => throw new NotImplementedException();
+ IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException();
+
+ // ============== IQueryable implementation ==============
+
+ public Type ElementType => throw new NotImplementedException();
+ public Expression Expression => throw new NotImplementedException();
+ public IQueryProvider Provider => throw new NotImplementedException();
+
+ // ============== Data methods implementation ==============
+
internal RequestUrlParameterParsingResult GetFullPath(string path, bool handleParameters, object[]? parameters = null)
{
if (ServiceOptions.BaseUrl is null) return new RequestUrlParameterParsingResult(path, string.Empty);
@@ -49,20 +76,6 @@ internal async Task HandleRequestAsync(HttpRequestMessage mess
}
}
- private class KeyNotFoundException : Exception
- {
- private static readonly string Msg = $"Unable to find TKey for type '{typeof(TModel).Name}'. Consider specifying a key when registering the set.";
- public KeyNotFoundException() : base(Msg) { }
- }
-
- public FluxRestSetContext(HttpClient httpClient, FluxRestServiceOptions serviceOptions, ILogger logger, FluxRestSetOptions setOptions)
- {
- HttpClient = httpClient;
- ServiceOptions = serviceOptions;
- _logger = logger;
- _setOptions = setOptions;
- }
-
public virtual async Task> GetAllAsync(params object[]? parameters)
{
var path = SetOptions.Endpoint is not null ? SetOptions.Endpoint : string.Empty;
@@ -105,7 +118,7 @@ public virtual async Task> GetPageAsync(PageRequest pageReque
public virtual async Task GetAsync(object? id, params object[]? parameters)
{
- if (SetOptions.GetIdEndpointAction is null) throw new KeyNotFoundException();
+ if (SetOptions.GetIdEndpointAction is null) throw new FluxRestKeyNotFoundException();
var idEndpoint = SetOptions.GetIdEndpointAction(id, parameters);
var parse = GetFullPath(idEndpoint, false);
@@ -129,48 +142,3 @@ protected string GetEndpoint()
return SetOptions.Endpoint;
}
}
-
-internal class FluxRestSetContext : FluxRestSetContext, IFluxSetContext
- where TModel : class
-{
- internal new FluxRestSetOptions SetOptions
- {
- get => (FluxRestSetOptions)_setOptions;
- set
- {
- _setOptions = value;
- }
- }
-
- public FluxRestSetContext(HttpClient httpClient, FluxRestServiceOptions serviceOptions, ILogger logger, FluxRestSetOptions setOptions)
- : base(httpClient, serviceOptions, logger, setOptions)
- {
- SetOptions = setOptions;
- }
-
- public override Task GetAsync(object? id, params object[]? parameters) => GetAsync((TKey?)id, parameters);
-
- public async Task GetAsync(TKey? id, params object[]? parameters)
- {
- string idEndpoint;
-
- bool handleParameters = false;
- if (SetOptions.GetIdEndpointAction is not null)
- {
- idEndpoint = SetOptions.GetIdEndpointAction(id, parameters);
- }
- else
- {
- idEndpoint = SetOptions.Endpoint is not null ? Path.Combine(SetOptions.Endpoint, id!.ToString()!) : id!.ToString()!;
- handleParameters = true;
- }
- var parse = GetFullPath(idEndpoint, handleParameters, parameters);
-
- _logger.LogInformation("Get {type}[{id}]: {route}{parsingLog}", typeof(TModel).Name, id!.ToString(), parse.Result, parse.Log);
-
- var message = new HttpRequestMessage(HttpMethod.Get, parse.Result);
- var result = await HandleRequestAsync(message);
-
- return result;
- }
-}
diff --git a/src/BitzArt.Flux.REST/Context/Models/RequestUrlParameterParsingResult.cs b/src/BitzArt.Flux.REST/Models/RequestUrlParameterParsingResult.cs
similarity index 100%
rename from src/BitzArt.Flux.REST/Context/Models/RequestUrlParameterParsingResult.cs
rename to src/BitzArt.Flux.REST/Models/RequestUrlParameterParsingResult.cs
diff --git a/src/BitzArt.Flux.REST/Context/Models/FluxRestServiceOptions.cs b/src/BitzArt.Flux.REST/Options/FluxRestServiceOptions.cs
similarity index 100%
rename from src/BitzArt.Flux.REST/Context/Models/FluxRestServiceOptions.cs
rename to src/BitzArt.Flux.REST/Options/FluxRestServiceOptions.cs
diff --git a/src/BitzArt.Flux.REST/Context/Models/FluxRestSetOptions.cs b/src/BitzArt.Flux.REST/Options/FluxRestSetOptions{TModel,TKey}.cs
similarity index 60%
rename from src/BitzArt.Flux.REST/Context/Models/FluxRestSetOptions.cs
rename to src/BitzArt.Flux.REST/Options/FluxRestSetOptions{TModel,TKey}.cs
index ebed5ca..34985c1 100644
--- a/src/BitzArt.Flux.REST/Context/Models/FluxRestSetOptions.cs
+++ b/src/BitzArt.Flux.REST/Options/FluxRestSetOptions{TModel,TKey}.cs
@@ -1,23 +1,5 @@
namespace BitzArt.Flux;
-public class FluxRestSetOptions
- where TModel : class
-{
- public string? Endpoint { get; set; }
- public string? PageEndpoint { get; set; }
- protected Func