RJDev.Core.Essentials
2.1.3
dotnet add package RJDev.Core.Essentials --version 2.1.3
NuGet\Install-Package RJDev.Core.Essentials -Version 2.1.3
<PackageReference Include="RJDev.Core.Essentials" Version="2.1.3" />
paket add RJDev.Core.Essentials --version 2.1.3
#r "nuget: RJDev.Core.Essentials, 2.1.3"
// Install RJDev.Core.Essentials as a Cake Addin #addin nuget:?package=RJDev.Core.Essentials&version=2.1.3 // Install RJDev.Core.Essentials as a Cake Tool #tool nuget:?package=RJDev.Core.Essentials&version=2.1.3
RJDev.Core.Essentials
Eseeentials you need in every project.
Registering with IServiceCollection
serviceCollection.AddRJDevCoreEssentials();
AppString
Object representing string inside an application.
record AppString(string Id, string? Description = null)
- Id - Text/message/error identifier which should be unique. Can be used as localization key.
- Description - Default text of the message.
The Id
property is important. This whole object can be sent from API to the FE, external services etc.
It is possible to identify each AppString and create custom localizations for each unique Id
.
Description
contains default message eg. in english.
Example
public static class AuthAppStrings
{
public static class Register
{
public static readonly AppString CreationFailed = new("Auth.Register.CreationFailed", "Account creation failed.");
}
public static class Auth
{
public static readonly AppString InvalidCredentials = new("Auth.Auth.InvalidCredentials", "Invalid credentials.");
public static readonly AppString NotAuthorized = new("Auth.Auth.NotAuthorized", "Your account is not authorized.");
public static readonly AppString Blocked = new("Auth.Auth.Blocked", "Your account has been blocked.");
}
}
class Something {
public AppString Auth(Some thing) {
if (/* ... */) return AuthAppStrings.Auth.InvalidCredentials;
// ...
if (!user.Authorized) return AuthAppStrings.Auth.NotAuthorized;
// ...
}
}
IAppStringFinder
If you use AppString like the example above, you can use IAppStringFinder
to find all the AppStrings in your application, so you can handle them in some way (eg. send them to FE, create localization files etc.).
/// <summary>
/// Interface for the service looking for all the statically declared <see cref="AppString"/> in application
/// so we know all the messages used in source code.
/// </summary>
public interface IAppStringFinder
{
/// <summary>
/// Returns collection of all the <see cref="AppString"/> declared in the application.
/// </summary>
/// <param name="cached">Use cached rasult or look for all the AppStrings again.</param>
/// <param name="assemblies">Which assemblies should be used. All assemblies in the bin will be used if no assemblies specified.</param>
/// <returns></returns>
IEnumerable<AppString> GetAllAppStrings(bool cached = true, Assembly[]? assemblies = null);
/// <summary>
/// Return <see cref="AppString"/> by its <see cref="AppString.Id"/> property.
/// </summary>
/// <param name="id"></param>
/// <param name="assemblies">Which assemblies should be used. All assemblies in the bin will be used if no assemblies specified.</param>
/// <returns></returns>
AppString GetAppString(string id, Assembly[]? assemblies = null);
}
Results
Types representing result of some operation. Interfaces IResult
, IResult<T>
and implementations Result
, Result<T>
.
Example
class AuthService
{
public IResult<User> Login(string username, string password)
{
if (username != "test" && password != "test")
{
return Result.Error<User>(AuthErrors.InvalidCredentials);
}
var user = new User(username, true);
if (!user.Authorized)
{
return Result.Error<User>(AuthErrors.AccountNotAuthorized);
}
return Result.Ok(user);
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- RJDev.Core.Reflection (>= 1.0.1)
-
.NETStandard 2.1
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- RJDev.Core.Reflection (>= 1.0.1)
-
net6.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- RJDev.Core.Reflection (>= 1.0.1)
-
net7.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- RJDev.Core.Reflection (>= 1.0.1)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- RJDev.Core.Reflection (>= 1.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.