-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace the term "Entity" with "Model"
- Loading branch information
1 parent
5b57a10
commit 01f1a4f
Showing
37 changed files
with
532 additions
and
412 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
sample/BitzArt.Flux.SampleApp/BitzArt.Flux.SampleApp.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\BitzArt.Flux.REST\BitzArt.Flux.REST.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace BitzArt.Flux.SampleApp.Models; | ||
|
||
public class Author | ||
{ | ||
[JsonPropertyName("id")] | ||
public int? Id { get; set; } | ||
|
||
[JsonPropertyName("name")] | ||
public string? Name { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace BitzArt.Flux.SampleApp.Models; | ||
|
||
public class Book | ||
{ | ||
[JsonPropertyName("id")] | ||
public int? Id { get; set; } | ||
|
||
[JsonPropertyName("title")] | ||
public string? Title { get; set; } | ||
|
||
[JsonPropertyName("description")] | ||
public string? Description { get; set; } | ||
|
||
[JsonPropertyName("author")] | ||
public string? Author { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using BitzArt.Flux.SampleApp.Models; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace BitzArt.Flux.SampleApp; | ||
|
||
internal class TestController : ControllerBase | ||
{ | ||
private readonly IFluxContext _flux; | ||
|
||
public TestController(IFluxContext flux) | ||
{ | ||
_flux = flux; | ||
} | ||
|
||
[HttpGet] | ||
public async Task<IActionResult> GetBookAsync() | ||
{ | ||
var book = await _flux.Model<Book>().GetAsync(1); | ||
|
||
return Ok(book); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using BitzArt.Flux.SampleApp.Models; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Options; | ||
using System.Text.Json.Serialization; | ||
|
||
namespace BitzArt.Flux.SampleApp; | ||
|
||
internal class Program | ||
{ | ||
private static void Main(string[] args) | ||
{ | ||
var services = new ServiceCollection(); | ||
|
||
services.AddFlux(x => | ||
{ | ||
x.AddService("library-api") | ||
.UsingRest("http://your-backend-url") | ||
.AddModel<Author>() | ||
.WithEndpoint("authors") | ||
.AddModel<Book>() | ||
.WithEndpoint("books") | ||
.WithPageEndpoint("authors/{authorId}/books"); | ||
|
||
x.AddService("library-api") | ||
.UsingRest("http://your-backend-url") | ||
.ConfigureHttpClient(client => | ||
{ | ||
client.DefaultRequestHeaders.Add("X-Api-Key", "MyApiKey"); | ||
}) | ||
.ConfigureJson(json => | ||
{ | ||
json.Converters.Add(new JsonStringEnumConverter()); | ||
}); | ||
}); | ||
|
||
var serviceProvider = services.BuildServiceProvider(); | ||
|
||
var flux = serviceProvider.GetRequiredService<IFluxContext>(); | ||
} | ||
} |
54 changes: 0 additions & 54 deletions
54
src/BitzArt.Flux.REST/Builder/Extensions/AddEntityExtension.cs
This file was deleted.
Oops, something went wrong.
54 changes: 54 additions & 0 deletions
54
src/BitzArt.Flux.REST/Builder/Extensions/AddModelExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace BitzArt.Flux; | ||
|
||
public static class AddModelExtension | ||
{ | ||
public static IFluxRestModelBuilder<TModel> AddModel<TModel>(this IFluxRestServiceBuilder serviceBuilder, string? endpoint = null) | ||
where TModel : class | ||
{ | ||
var builder = new FluxRestModelBuilder<TModel>(serviceBuilder); | ||
|
||
var services = serviceBuilder.Services; | ||
var serviceContext = builder.ServiceFactory; | ||
|
||
serviceContext.AddModel<TModel>(builder.ModelOptions); | ||
|
||
services.AddScoped(x => | ||
{ | ||
var factory = x.GetRequiredService<IFluxFactory>(); | ||
return factory.GetModelContext<TModel>(x, serviceContext.ServiceName); | ||
}); | ||
|
||
if (endpoint is not null) return builder.WithEndpoint(endpoint); | ||
|
||
return builder; | ||
} | ||
|
||
public static IFluxRestModelBuilder<TModel, TKey> AddModel<TModel, TKey>(this IFluxRestServiceBuilder serviceBuilder, string? endpoint = null) | ||
where TModel : class | ||
{ | ||
var builder = new FluxRestModelBuilder<TModel, TKey>(serviceBuilder); | ||
|
||
var services = serviceBuilder.Services; | ||
var serviceContext = serviceBuilder.ServiceFactory; | ||
|
||
serviceContext.AddModel<TModel, TKey>(builder.ModelOptions); | ||
|
||
services.AddScoped(x => | ||
{ | ||
var provider = x.GetRequiredService<IFluxFactory>(); | ||
return provider.GetModelContext<TModel, TKey>(x, serviceContext.ServiceName); | ||
}); | ||
|
||
services.AddScoped<IFluxModelContext<TModel>>(x => | ||
{ | ||
var provider = x.GetRequiredService<IFluxFactory>(); | ||
return provider.GetModelContext<TModel, TKey>(x, serviceContext.ServiceName); | ||
}); | ||
|
||
if (endpoint is not null) return builder.WithEndpoint(endpoint); | ||
|
||
return builder; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.