Wlvyr.Common
0.3.0
dotnet add package Wlvyr.Common --version 0.3.0
NuGet\Install-Package Wlvyr.Common -Version 0.3.0
<PackageReference Include="Wlvyr.Common" Version="0.3.0" />
<PackageVersion Include="Wlvyr.Common" Version="0.3.0" />
<PackageReference Include="Wlvyr.Common" />
paket add Wlvyr.Common --version 0.3.0
#r "nuget: Wlvyr.Common, 0.3.0"
#:package Wlvyr.Common@0.3.0
#addin nuget:?package=Wlvyr.Common&version=0.3.0
#tool nuget:?package=Wlvyr.Common&version=0.3.0
Wlvyr.Common
Wlvyr.Common is a library created to aid in common project setup.
Dependency Injection
To help facilitate in loading dependency injection (DI) service across different projects, Wlvyr.Common.Interface.Configuration.IDIConfig<TContainer, TSettings> provides an interface in configuring your DI in all required projects. Then, binding and initializing the DI configurations from Wlvyr.Common.Configuration.DIBootstrap<TContainer, TAppSettings>.
An example in initializing DIBootstrap with SimpleInjector:
using SimpleInjector;
using Wlvyr.Common.Configuration;
using Wlvyr.Common.Reflection;
namespace MainProject;
public static void Main(){
// Example to get configuration.
var builder = WebApplication.CreateBuilder(args);
// Access IConfiguration
IConfiguration configuration = builder.Configuration; // or new ConfigurationBuilder().AddJsonFile("appsettings.json") .Build()
IEnumerable<Assembly> assemblies = AssemblyHelper.GetAssemblies(
nameIncludes: new HashSet<string>(){
"asssembly.only-included-project.name1",
"assembly.only-included-project.name2"
}
);
var diConfig = new DIBootstrapConfiguration<AppSettings>(
new AppSettings(configuration),
new HashSet<string> { "Some.Namespace.ExcludedDIConfig" } // excluded IDIconfig from being configured. empty for all to be included
);
var diBootstrap = new DIBootstrap(
diConfig,
() => new SimpleInjector.Container(),
() => assemblies.CreateDIConfigs<Container, TAppSettings>(diConfig.ExcludedDIConfigFullNames) // from DIExtensions.CreateDIConfigs<Container, AppSettings>
);
diBootstrap.Initialize();
// d.DIContainer can now be used. example next step: Verify the DI container of your choice that it did bootstrap properly. (DIContainer.Verify is from SimpleInjector)
d.DIContainer.Verify();
}
Then, in a project that may not require Wlvyr.Common but only its interface, Wlvyr.Common.Interface, an implementation of IDIConfig will look like this:
using SimpleInjector;
using Wlvyr.Common.Interface.Configuration;
namespace SomeProject;
public class SomeDIConfig : IDIConfig<Container, SomeAppSetting> {
public void Configure(Container container, SomeAppSetting configuration){
container.Register<ILogger, FileLogger>();
}
}
Mapper
Allow projects to define their own mapping configuration. The project doesn't require AutoMapper to be used, but is based on it. To setup, get all Wlvyr.Common.Interface.Configuration.IMapperConfig<TConfigurer> implementations, from relevant workspace projects, and then initialize.
Example usage:
using AutoMapper;
using Wlvyr.Common.Configuration;
using Wlvyr.Common.Reflection;
namespace MainProject;
public static void Main()
{
IEnumerable<Assembly> assemblies = AssemblyHelper.GetAssemblies(
new HashSet<string>(){ "asssembly.project.name1", "assembly.project.name2" }
);
Func<MapperConfigurationExpression> cfgExpFactory = () => MapperConfigurationExpression();
Func<MapperConfigurationExpression, IMapper> mapperFactory = (cfg) => new MapperConfiguration(cfg).CreateMapper();
Func<IEnumerable<IMapperConfig<MapperConfigurationExpression>>> mapperConfigsFactory = () => assemblies.CreateMapperConfigs<MapperConfigurationExpression>(/*optionAppSettings*/); // from MappingExtensions
var b = new MapperBootstrap<IMapper, MapperConfigurationExpression>(
cfgExpFactory,
mapperFactory,
mapperConfigsFactory,
);
b.Initialize();
// b.Mapper; can now be accessed. b.Mapper will throw an error if it has not been initialized.
// b.Mapper can be registered to a DI container. e.g. diBootstrap.DIContainer.RegisterInstance(b.Mapper);
}
Then, in a project that may not require Wlvyr.Common but only its interface, Wlvyr.Common.Interface, an implementation of IMapperConfig will look like this:
using SimpleInjector;
using Wlvyr.Common.Interface.Configuration;
namespace SomeProject;
public class SomeMapperConfig : IMapperConfig<MapperConfigurationExpression> {
public void Configure(MapperConfigurationExpression cfg){
cfg.CreateMap<Employee, EmployeeDTO>();
}
}
// If appSettings is not included in assemblies.CreateMapperConfigs<MapperConfigurationExpression>(), this will not be included.
public class SomeMapperConfigWithAppSettingParam : IMapperConfig<MapperConfigurationExpression> {
public SomeMapperConfigWithAppSettingParam(AppSettings appSettings){
this.AppSettings = appSettings;
}
protected AppSettings AppSettings { get; init; }
public void Configure(MapperConfigurationExpression cfg){
cfg.CreateMap<Employee, EmployeeDTO>();
}
}
| 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. 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.Extensions.Configuration (>= 7.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 7.0.4)
- Wlvyr.Common.Interface (>= 0.2.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Wlvyr.Common:
| Package | Downloads |
|---|---|
|
Wlvyr.Common.DI.SimpleInjector
A helper library that simplifies common setup patterns and configurations for the SimpleInjector dependency injection container. |
GitHub repositories
This package is not used by any popular GitHub repositories.
- **0.3.0**: Result/Result<T> breaking changes
- Replaced success flag with ResultStatus; removed parameterless/bool constructors
- **0.2.4**: Updated project metadata
- **0.2.3**: Mapper
- MappingExtensions.CreateMapperConfigs now allows IAppSettings to be included
- IMapperConfig implementation either have parameterless constructor or constructor with IAppSettings as parameter.