diff --git a/README.md b/README.md index f30a20f..d3e201c 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,9 @@ A framework to simplify application creation by improving dependency injection, ```csharp using Config.Net; -using Lina.AutoDependencyInjection; -using Lina.AutoDependencyInjection.Attributes; -using Lina.LoaderConfig; +using TakasakiStudio.Lina.AutoDependencyInjection; +using TakasakiStudio.Lina.AutoDependencyInjection.Attributes; +using TakasakiStudio.Lina.Utils.LoaderConfig; using Microsoft.Extensions.DependencyInjection; var serviceCollection = new ServiceCollection(); @@ -43,7 +43,7 @@ public interface IFooService public void PrintAppName(); } -[Service(typeof(IFooService))] +[Service] public class FooService : IFooService { private readonly IAppConfig _appConfig; @@ -70,7 +70,7 @@ public interface IAppConfig ```csharp using Config.Net; -using Lina.LoaderConfig; +using TakasakiStudio.Lina.Utils.LoaderConfig; using Microsoft.Extensions.DependencyInjection; var serviceCollection = new ServiceCollection(); @@ -94,9 +94,9 @@ public interface IAppConfig ```csharp using Config.Net; -using Lina.Database; -using Lina.Database.Models; -using Lina.LoaderConfig; +using TakasakiStudio.Lina.Database; +using TakasakiStudio.Lina.Database.Models; +using TakasakiStudio.Lina.Utils.LoaderConfig; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.Extensions.DependencyInjection; @@ -134,8 +134,8 @@ public class UserConfiguration : IEntityTypeConfiguration ```csharp using FluentValidation; -using Lina.Database.Models; -using Lina.ViewModels; +using TakasakiStudio.Lina.Common; +using TakasakiStudio.Lina.Database.Models; var user = new User() { @@ -166,7 +166,7 @@ public class UserValidation : AbstractValidator } } -public record UserViewModel() : BaseViewModel +public record UserViewModel() : BaseValidationRecord { public string Name { get; set; } = string.Empty; } @@ -185,16 +185,17 @@ public class UserViewModelValidation : AbstractValidator ```csharp using Config.Net; using FluentValidation; -using Lina.Database; -using Lina.Database.Interfaces; -using Lina.Database.Models; -using Lina.Database.Repositories; -using Lina.AutoDependencyInjection.Attributes; -using Lina.LoaderConfig; -using Lina.ViewModels; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.Extensions.DependencyInjection; +using TakasakiStudio.Lina.AutoDependencyInjection; +using TakasakiStudio.Lina.AutoDependencyInjection.Attributes; +using TakasakiStudio.Lina.Common; +using TakasakiStudio.Lina.Database; +using TakasakiStudio.Lina.Database.Interfaces; +using TakasakiStudio.Lina.Database.Models; +using TakasakiStudio.Lina.Database.Repositories; +using TakasakiStudio.Lina.Utils.LoaderConfig; var serviceCollection = new ServiceCollection(); @@ -204,7 +205,7 @@ serviceCollection.AddLinaDbContext((builder, assembly) => builder.UseMySql(config.DatabaseUrl, ServerVersion.AutoDetect(config.DatabaseUrl), optionsBuilder => optionsBuilder.MigrationsAssembly(assembly))); -public interface IAppConfig +public interface IAppConfig { [Option(DefaultValue = "Server=localhost;Database=test;User Id=root;Password=root;")] public string DatabaseUrl { get; } @@ -216,7 +217,7 @@ public class User : BaseValidateBaseEntity public static implicit operator User(UserViewModel viewModel) { - return new User() + return new User { Name = viewModel.Name }; @@ -224,7 +225,7 @@ public class User : BaseValidateBaseEntity public static implicit operator UserViewModel(User user) { - return new UserViewModel() + return new UserViewModel { Name = user.Name }; @@ -249,7 +250,7 @@ public class UserConfiguration : IEntityTypeConfiguration } } -public record UserViewModel() : BaseViewModel +public record UserViewModel : BaseValidationRecord { public string Name { get; set; } = string.Empty; } @@ -266,7 +267,7 @@ public interface IUserRepository : IBaseRepository { } -[Repository(typeof(IUserRepository))] +[Repository] public class UserRepository : BaseRepository, IUserRepository { public UserRepository(DbContext dbContext) : base(dbContext) @@ -278,7 +279,7 @@ public interface IUserService { } -[Service(typeof(IUserService))] +[Service] public class UserService : IUserService { private readonly IUserRepository _userRepository; @@ -290,11 +291,8 @@ public class UserService : IUserService public async Task Add(UserViewModel userViewModel) { - if (!await userViewModel.IsValid()) - { - throw new Exception("Not valid"); - } - + if (!await userViewModel.IsValid()) throw new Exception("Not valid"); + User user = userViewModel; await user.Validate(); @@ -311,4 +309,3 @@ public class UserService : IUserService - [Config.Net](https://github.com/aloneguid/config) - [FluentValidation](https://docs.fluentvalidation.net/en/latest/) - [EntityFramework](https://learn.microsoft.com/en-us/ef/core/) -- [AutoMapper](https://docs.automapper.org/en/stable/) (Obsolete) diff --git a/TakasakiStudio.Lina.AspNet/ActionResults/BlazorComponentRenderActionResult.cs b/TakasakiStudio.Lina.AspNet/ActionResults/BlazorComponentRenderActionResult.cs index 5ef1cf5..74b8818 100644 --- a/TakasakiStudio.Lina.AspNet/ActionResults/BlazorComponentRenderActionResult.cs +++ b/TakasakiStudio.Lina.AspNet/ActionResults/BlazorComponentRenderActionResult.cs @@ -4,9 +4,18 @@ namespace TakasakiStudio.Lina.AspNet.ActionResults; +/// +/// Blazor Component render result +/// +/// Params for Blazor Component +/// Blazor Component type public class BlazorComponentRenderActionResult(object? componentParams = null) : IActionResult where T : IComponent { + /// + /// Execute render + /// + /// Request context public async Task ExecuteResultAsync(ActionContext context) { var blazorRender = componentParams is null diff --git a/TakasakiStudio.Lina.AspNet/Controllers/PageController.cs b/TakasakiStudio.Lina.AspNet/Controllers/PageController.cs index 97ad3db..e82e369 100644 --- a/TakasakiStudio.Lina.AspNet/Controllers/PageController.cs +++ b/TakasakiStudio.Lina.AspNet/Controllers/PageController.cs @@ -4,8 +4,17 @@ namespace TakasakiStudio.Lina.AspNet.Controllers; +/// +/// Custom controller for render Blazor Components +/// public abstract class PageController : Controller { + /// + /// Return render Blazor Component + /// + /// Params for Blazor Component + /// Blazor Component type + /// protected static IActionResult RenderComponent(object? componentParams = null) where T : IComponent => new BlazorComponentRenderActionResult(componentParams); diff --git a/TakasakiStudio.Lina.AspNet/TakasakiStudio.Lina.AspNet.csproj b/TakasakiStudio.Lina.AspNet/TakasakiStudio.Lina.AspNet.csproj index 01fd1d3..733b812 100644 --- a/TakasakiStudio.Lina.AspNet/TakasakiStudio.Lina.AspNet.csproj +++ b/TakasakiStudio.Lina.AspNet/TakasakiStudio.Lina.AspNet.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 2.0.0-rc.1 + 2.0.0-rc.2 true TakasakiStudio.Lina.AspNet TakasakiStudio diff --git a/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/AdapterAttribute.cs b/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/AdapterAttribute.cs index 44480ac..5f7b1a0 100644 --- a/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/AdapterAttribute.cs +++ b/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/AdapterAttribute.cs @@ -9,7 +9,7 @@ namespace TakasakiStudio.Lina.AutoDependencyInjection.Attributes; /// } /// /// -/// [Adapter(typeof(IFooAdapter))] +/// [Adapter<IFooAdapter>] /// class FooAdapter : IFooAdapter { /// /*...*/ /// } diff --git a/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/DependencyAttribute.cs b/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/DependencyAttribute.cs index 79cbb74..caebe88 100644 --- a/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/DependencyAttribute.cs +++ b/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/DependencyAttribute.cs @@ -9,7 +9,7 @@ namespace TakasakiStudio.Lina.AutoDependencyInjection.Attributes; /// } /// /// -/// [Dependency(typeof(IFooDependency), LifeTime.Scoped)] +/// [Dependency<IFooDependency>(LifeTime.Scoped)] /// class FooDependency : IFooDependency { /// /*...*/ /// } diff --git a/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/HttpClientAttribute.cs b/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/HttpClientAttribute.cs index d89c9df..718853f 100644 --- a/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/HttpClientAttribute.cs +++ b/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/HttpClientAttribute.cs @@ -9,7 +9,7 @@ namespace TakasakiStudio.Lina.AutoDependencyInjection.Attributes; /// } /// /// -/// [HttpClient(typeof(IFooHttpClient))] +/// [HttpClient<IFooHttpClient>] /// class FooHttpClient : IFooHttpClient { /// /*...*/ /// } diff --git a/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/MiddlewareAttribute.cs b/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/MiddlewareAttribute.cs index 6e1df3a..7aebac0 100644 --- a/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/MiddlewareAttribute.cs +++ b/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/MiddlewareAttribute.cs @@ -9,7 +9,7 @@ namespace TakasakiStudio.Lina.AutoDependencyInjection.Attributes; /// } /// /// -/// [Middleware(typeof(IFooMiddleware))] +/// [Middleware<IFooMiddleware>] /// class FooMiddleware : IFooMiddleware { /// /*...*/ /// } diff --git a/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/RepositoryAttribute.cs b/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/RepositoryAttribute.cs index 7ab51a2..45848c9 100644 --- a/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/RepositoryAttribute.cs +++ b/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/RepositoryAttribute.cs @@ -9,7 +9,7 @@ namespace TakasakiStudio.Lina.AutoDependencyInjection.Attributes; /// } /// /// -/// [Repository(typeof(IFooRepository))] +/// [Repository<IFooRepository>] /// class FooRepository : IFooRepository { /// /*...*/ /// } diff --git a/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/ServiceAttribute.cs b/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/ServiceAttribute.cs index 2245555..572bb08 100644 --- a/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/ServiceAttribute.cs +++ b/TakasakiStudio.Lina.AutoDependencyInjection/Attributes/ServiceAttribute.cs @@ -9,7 +9,7 @@ namespace TakasakiStudio.Lina.AutoDependencyInjection.Attributes; /// } /// /// -/// [Service(typeof(IFooService))] +/// [Service<IFooService>] /// class FooService : IFooService { /// /*...*/ /// } diff --git a/TakasakiStudio.Lina.AutoDependencyInjection/TakasakiStudio.Lina.AutoDependencyInjection.csproj b/TakasakiStudio.Lina.AutoDependencyInjection/TakasakiStudio.Lina.AutoDependencyInjection.csproj index 9150c4d..91960b4 100644 --- a/TakasakiStudio.Lina.AutoDependencyInjection/TakasakiStudio.Lina.AutoDependencyInjection.csproj +++ b/TakasakiStudio.Lina.AutoDependencyInjection/TakasakiStudio.Lina.AutoDependencyInjection.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 2.0.0-rc.1 + 2.0.0-rc.2 true TakasakiStudio.Lina.AutoDependencyInjection TakasakiStudio diff --git a/TakasakiStudio.Lina.Common/TakasakiStudio.Lina.Common.csproj b/TakasakiStudio.Lina.Common/TakasakiStudio.Lina.Common.csproj index 102ce7d..5968e4d 100644 --- a/TakasakiStudio.Lina.Common/TakasakiStudio.Lina.Common.csproj +++ b/TakasakiStudio.Lina.Common/TakasakiStudio.Lina.Common.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 2.0.0-rc.1 + 2.0.0-rc.2 true TakasakiStudio.Lina.Common TakasakiStudio.Lina.Common diff --git a/TakasakiStudio.Lina.Database/Models/BaseEntity.cs b/TakasakiStudio.Lina.Database/Models/BaseEntity.cs index 15bd4c2..446f2bc 100644 --- a/TakasakiStudio.Lina.Database/Models/BaseEntity.cs +++ b/TakasakiStudio.Lina.Database/Models/BaseEntity.cs @@ -11,6 +11,11 @@ public abstract class BaseEntity /// public TPkType Id { get; set; } = default!; + /// + /// Create a clone of value + /// + /// Value type + /// public T Clone() where T: BaseEntity { diff --git a/TakasakiStudio.Lina.Database/Models/BaseValidateBaseEntity.cs b/TakasakiStudio.Lina.Database/Models/BaseValidateBaseEntity.cs index 6257d2c..d43c4ce 100644 --- a/TakasakiStudio.Lina.Database/Models/BaseValidateBaseEntity.cs +++ b/TakasakiStudio.Lina.Database/Models/BaseValidateBaseEntity.cs @@ -15,16 +15,27 @@ public abstract class BaseValidateBaseEntity : IBaseValidate where TValidationClass: IValidator { + /// + /// Validate entity and throw if invalid + /// public virtual async ValueTask Validate() { await GetBaseImplementationInstance().BaseValidate(); } + /// + /// Get validation errors + /// + /// Errors public virtual async Task GetErrors() { return await GetBaseImplementationInstance().BaseGetErrors(); } + /// + /// Entity is valid + /// + /// Is valid public virtual async ValueTask IsValid() { return await GetBaseImplementationInstance().BaseIsValid(); diff --git a/TakasakiStudio.Lina.Database/TakasakiStudio.Lina.Database.csproj b/TakasakiStudio.Lina.Database/TakasakiStudio.Lina.Database.csproj index b38449d..72e31e5 100644 --- a/TakasakiStudio.Lina.Database/TakasakiStudio.Lina.Database.csproj +++ b/TakasakiStudio.Lina.Database/TakasakiStudio.Lina.Database.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 2.0.0-rc.1 + 2.0.0-rc.2 true TakasakiStudio.Lina.Database TakasakiStudio.Lina.Database diff --git a/TakasakiStudio.Lina.Utils/Extensions/EnumExtensions.cs b/TakasakiStudio.Lina.Utils/Extensions/EnumExtensions.cs index 93bcfed..177e6df 100644 --- a/TakasakiStudio.Lina.Utils/Extensions/EnumExtensions.cs +++ b/TakasakiStudio.Lina.Utils/Extensions/EnumExtensions.cs @@ -4,6 +4,11 @@ namespace TakasakiStudio.Lina.Utils.Extensions; public static class EnumExtensions { + /// + /// Convert enum as option + /// + /// Enum type + /// Options public static IDictionary GetOptions() where T : struct, Enum { @@ -23,12 +28,24 @@ public static IDictionary GetOptions() .ToDictionary(x => x.Item2.ToString()!, y => y.Item1.ToString()); } + /// + /// Get enum value + /// + /// Enum + /// Enum type + /// Value public static string GetValue(this T? value) where T : struct, Enum { return value is null ? "" : Convert.ToInt32(value).ToString(); } + /// + /// Unify flag list to unique value + /// + /// Flag list + /// Enum type + /// Enum value public static T ToFlags(this IEnumerable list) where T : struct, Enum { @@ -46,6 +63,12 @@ public static T ToFlags(this IEnumerable list) return (T)Enum.ToObject(typeof(T), Convert.ChangeType(result, underlyingType)); } + /// + /// Split enum flag into list + /// + /// Enum value + /// Enum type + /// Flag list public static IEnumerable ToEnumerable(this T flag) where T : struct, Enum { diff --git a/TakasakiStudio.Lina.Utils/Extensions/QueryableExtensions.cs b/TakasakiStudio.Lina.Utils/Extensions/QueryableExtensions.cs index a04426c..ac9576d 100644 --- a/TakasakiStudio.Lina.Utils/Extensions/QueryableExtensions.cs +++ b/TakasakiStudio.Lina.Utils/Extensions/QueryableExtensions.cs @@ -13,7 +13,7 @@ public static class QueryableExtensions /// Page size /// Model type /// Query execution - public static IQueryable Paginate(this IQueryable query, int page, int pageSize) + public static IQueryable Paginate(this IQueryable query, int page, int pageSize = 20) { if (page == 0) page = 1; @@ -25,4 +25,4 @@ public static IQueryable Paginate(this IQueryable query, int page, int return query.Skip((page - 1) * pageSize).Take(pageSize); } -} \ No newline at end of file +} diff --git a/TakasakiStudio.Lina.Utils/TakasakiStudio.Lina.Utils.csproj b/TakasakiStudio.Lina.Utils/TakasakiStudio.Lina.Utils.csproj index 76683e8..634d66d 100644 --- a/TakasakiStudio.Lina.Utils/TakasakiStudio.Lina.Utils.csproj +++ b/TakasakiStudio.Lina.Utils/TakasakiStudio.Lina.Utils.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 2.0.0-rc.1 + 2.0.0-rc.2 true TakasakiStudio.Lina.Utils TakasakiStudio.Lina.Utils diff --git a/TakasakiStudio.Lina/TakasakiStudio.Lina.csproj b/TakasakiStudio.Lina/TakasakiStudio.Lina.csproj index 7fcd400..3b9c2eb 100644 --- a/TakasakiStudio.Lina/TakasakiStudio.Lina.csproj +++ b/TakasakiStudio.Lina/TakasakiStudio.Lina.csproj @@ -4,7 +4,7 @@ net8.0 enable enable - 2.0.0-rc.1 + 2.0.0-rc.2 true TakasakiStudio.Lina TakasakiStudio.Lina