TakasakiStudio.Lina
2.0.8
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package TakasakiStudio.Lina --version 2.0.8
NuGet\Install-Package TakasakiStudio.Lina -Version 2.0.8
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TakasakiStudio.Lina" Version="2.0.8" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TakasakiStudio.Lina --version 2.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TakasakiStudio.Lina, 2.0.8"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TakasakiStudio.Lina as a Cake Addin #addin nuget:?package=TakasakiStudio.Lina&version=2.0.8 // Install TakasakiStudio.Lina as a Cake Tool #tool nuget:?package=TakasakiStudio.Lina&version=2.0.8
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Lina
A framework to simplify application creation by improving dependency injection, validation, config and database handling
Features
- Config
- Easy load
- Auto inject
- Database
- Auto inject
- Auto import configuration
- Easy configuration
- Validation
- Fluent api
- Reliable library
- Easy usage
- Dependency Injection
- Life time configurable
- Easy manipulation
- Services, Repositories, HttpClient and more types of preconfigured dependencies
- Asp Net Core
- Blazor render component in controller
- Clear hosted lifecycle
Example simple usage
using Config.Net;
using TakasakiStudio.Lina.AutoDependencyInjection;
using TakasakiStudio.Lina.AutoDependencyInjection.Attributes;
using TakasakiStudio.Lina.Utils.LoaderConfig;
using Microsoft.Extensions.DependencyInjection;
var serviceCollection = new ServiceCollection();
serviceCollection.AddLoaderConfig<IAppConfig>();
serviceCollection.AddAutoDependencyInjection<Program>();
var services = serviceCollection.BuildServiceProvider();
services.GetRequiredService<IFooService>().PrintAppName();
public interface IFooService
{
public void PrintAppName();
}
[Service<IFooService>]
public class FooService : IFooService
{
private readonly IAppConfig _appConfig;
public FooService(IAppConfig appConfig)
{
_appConfig = appConfig;
}
public void PrintAppName()
{
Console.WriteLine(_appConfig.AppName);
}
}
public interface IAppConfig
{
[Option(DefaultValue = "Test")]
public string AppName { get; }
}
Config example usage
using Config.Net;
using TakasakiStudio.Lina.Utils.LoaderConfig;
using Microsoft.Extensions.DependencyInjection;
var serviceCollection = new ServiceCollection();
var config = serviceCollection.AddLoaderConfig<IAppConfig>();
Console.WriteLine(config.AppName); // instant use
var services = serviceCollection.BuildServiceProvider();
Console.WriteLine(services.GetRequiredService<IAppConfig>().AppName); // DI usage
public interface IAppConfig
{
[Option(DefaultValue = "Test")]
public string AppName { get; }
}
Database example usage
using Config.Net;
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;
var serviceCollection = new ServiceCollection();
var config = serviceCollection.AddLoaderConfig<IAppConfig>();
serviceCollection.AddLinaDbContext<Program>((builder, assembly) =>
builder.UseMySql(config.DatabaseUrl, ServerVersion.AutoDetect(config.DatabaseUrl),
optionsBuilder => optionsBuilder.MigrationsAssembly(assembly)));
public interface IAppConfig
{
[Option(DefaultValue = "Server=localhost;Database=test;User Id=root;Password=root;")]
public string DatabaseUrl { get; }
}
public class User : BaseEntity<int>
{
public string Name { get; set; } = string.Empty;
}
public class UserConfiguration : IEntityTypeConfiguration<User>
{
public void Configure(EntityTypeBuilder<User> builder)
{
builder.ToTable("Users");
builder.HasKey(x => x.Id);
builder.Property(x => x.Name).IsRequired();
}
}
Validation example usage
using FluentValidation;
using TakasakiStudio.Lina.Common;
using TakasakiStudio.Lina.Database.Models;
var user = new User()
{
Name = ""
};
if (!await user.IsValid())
{
Console.WriteLine("invalid");
}
user.Name = "Foo";
await user.Validate();
Console.WriteLine("Valid");
public class User : BaseEntityValidate<User, UserValidation, int>
{
public string Name { get; set; } = string.Empty;
}
public class UserValidation : AbstractValidator<User>
{
public UserValidation()
{
RuleFor(x => x.Name).NotEmpty();
}
}
public record UserViewModel() : BaseValidationRecord<UserViewModel, UserViewModelValidation>
{
public string Name { get; set; } = string.Empty;
}
public class UserViewModelValidation : AbstractValidator<UserViewModel>
{
public UserViewModelValidation()
{
RuleFor(x => x.Name).NotEmpty();
}
}
Dependency injection example usage
using Config.Net;
using FluentValidation;
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();
var config = serviceCollection.AddLoaderConfig<IAppConfig>();
serviceCollection.AddAutoDependencyInjection<Program>();
serviceCollection.AddLinaDbContext<Program>((builder, assembly) =>
builder.UseMySql(config.DatabaseUrl, ServerVersion.AutoDetect(config.DatabaseUrl),
optionsBuilder => optionsBuilder.MigrationsAssembly(assembly)));
public interface IAppConfig
{
[Option(DefaultValue = "Server=localhost;Database=test;User Id=root;Password=root;")]
public string DatabaseUrl { get; }
}
public class User : BaseValidateBaseEntity<User, UserValidation, int>
{
public string Name { get; set; } = string.Empty;
public static implicit operator User(UserViewModel viewModel)
{
return new User
{
Name = viewModel.Name
};
}
public static implicit operator UserViewModel(User user)
{
return new UserViewModel
{
Name = user.Name
};
}
}
public class UserValidation : AbstractValidator<User>
{
public UserValidation()
{
RuleFor(x => x.Name).NotEmpty();
}
}
public class UserConfiguration : IEntityTypeConfiguration<User>
{
public void Configure(EntityTypeBuilder<User> builder)
{
builder.ToTable("Users");
builder.HasKey(x => x.Id);
builder.Property(x => x.Name).IsRequired();
}
}
public record UserViewModel : BaseValidationRecord<UserViewModel, UserViewModelValidation>
{
public string Name { get; set; } = string.Empty;
}
public class UserViewModelValidation : AbstractValidator<UserViewModel>
{
public UserViewModelValidation()
{
RuleFor(x => x.Name).NotEmpty();
}
}
public interface IUserRepository : IBaseRepository<User, int>
{
}
[Repository<IUserRepository>]
public class UserRepository : BaseRepository<User, int>, IUserRepository
{
public UserRepository(DbContext dbContext) : base(dbContext)
{
}
}
public interface IUserService
{
}
[Service<IUserService>]
public class UserService : IUserService
{
private readonly IUserRepository _userRepository;
public UserService(IUserRepository userRepository)
{
_userRepository = userRepository;
}
public async Task<UserViewModel?> Add(UserViewModel userViewModel)
{
if (!await userViewModel.IsValid()) throw new Exception("Not valid");
User user = userViewModel;
await user.Validate();
await _userRepository.Add(user);
await _userRepository.Commit();
return user;
}
}
Blazor components
using Microsoft.AspNetCore.Mvc;
using TakasakiStudio.Lina.AspNet.Controllers;
[Controller]
public class AuthController() : PageController
{
[HttpGet]
public IActionResult Login()
{
return RenderComponent<LoginPage>(); // LoginPage is a Blazor component
}
}
Clear hosted lifecycle
using TakasakiStudio.Lina.AspNet.Workers;
public class MyWorker : AbstractHostedLifecycleService
{
public override Task StartingAsync(CancellationToken cancellationToken)
{
/*...*/
}
}
Libraries usage
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- TakasakiStudio.Lina.AutoDependencyInjection (>= 2.0.8)
- TakasakiStudio.Lina.Common (>= 2.0.8)
- TakasakiStudio.Lina.Database (>= 2.0.8)
- TakasakiStudio.Lina.Utils (>= 2.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.3.0 | 67 | 11/18/2024 |
2.2.1 | 80 | 10/17/2024 |
2.2.0 | 216 | 10/9/2024 |
2.1.7 | 89 | 10/2/2024 |
2.1.6 | 334 | 8/30/2024 |
2.1.5 | 106 | 7/19/2024 |
2.1.4 | 114 | 6/27/2024 |
2.1.3 | 107 | 6/5/2024 |
2.1.2 | 194 | 5/15/2024 |
2.1.1 | 97 | 5/13/2024 |
2.0.13 | 89 | 5/13/2024 |
2.0.12 | 144 | 5/5/2024 |
2.0.11 | 100 | 5/5/2024 |
2.0.10 | 121 | 4/13/2024 |
2.0.9 | 107 | 3/31/2024 |
2.0.8 | 107 | 3/18/2024 |
2.0.7 | 118 | 3/17/2024 |
2.0.6 | 117 | 2/22/2024 |
2.0.5 | 113 | 2/14/2024 |
2.0.4 | 111 | 2/7/2024 |
2.0.3 | 113 | 1/21/2024 |
2.0.2 | 265 | 11/28/2023 |
2.0.1 | 145 | 11/23/2023 |
2.0.0 | 128 | 11/22/2023 |
1.2.12 | 111 | 6/28/2024 |
1.2.11 | 109 | 4/13/2024 |
1.2.10 | 122 | 2/22/2024 |
1.2.9 | 109 | 1/21/2024 |
1.2.8 | 121 | 12/17/2023 |
1.2.7 | 133 | 11/15/2023 |
1.2.6 | 135 | 11/10/2023 |
1.2.5 | 143 | 11/9/2023 |
1.2.4 | 163 | 11/7/2023 |
1.2.3 | 164 | 10/29/2023 |
1.2.2 | 157 | 10/1/2023 |
1.2.1 | 138 | 10/1/2023 |