DotNetStarter.Extensions.Registrations.AspNetCore
0.1.0
See the version list below for details.
dotnet add package DotNetStarter.Extensions.Registrations.AspNetCore --version 0.1.0
NuGet\Install-Package DotNetStarter.Extensions.Registrations.AspNetCore -Version 0.1.0
<PackageReference Include="DotNetStarter.Extensions.Registrations.AspNetCore" Version="0.1.0" />
paket add DotNetStarter.Extensions.Registrations.AspNetCore --version 0.1.0
#r "nuget: DotNetStarter.Extensions.Registrations.AspNetCore, 0.1.0"
// Install DotNetStarter.Extensions.Registrations.AspNetCore as a Cake Addin #addin nuget:?package=DotNetStarter.Extensions.Registrations.AspNetCore&version=0.1.0 // Install DotNetStarter.Extensions.Registrations.AspNetCore as a Cake Tool #tool nuget:?package=DotNetStarter.Extensions.Registrations.AspNetCore&version=0.1.0
DotNetStarter.Extensions.Registrations Read Me
The extensions provided in this project focus only on the dependency injection component of DotNetStarter. If the full DotNetStarter package is installed, these extensions should not be used. These extensions provide service registration to AspNetCore's dependency injection or Episerver's service configuration utilizing the DotNetStarter.RegistrationAttribute attribute on class types that implement abstract services.
AspNetCore Service Wireup
To add registrations to AspNetCore applications, simply use the provided AddDotNetStarterRegistrations() extension to the service collection in the application startup class.
// using DotNetStarter.Extensions.Registrations.AspNetCore;
public void ConfigureServices(IServiceCollection services)
{
services.AddDotNetStarterRegistrations();
}
Episerver Cms Wireup
By default, the Episerver extension requires no additional work other than installing its Nuget Package of DotNetStarter.Extensions.Registrations.EpiserverCms
The assembly loading and registration sorting can be customized by setting InitializeDotNetStarterRegistrations.ModuleEnabled equal to false in a PreApplicationStartMethod as show in the optional sample code below:
using DotNetStarter.Extensions.Registrations.EpiserverCms;
using EPiServer.Framework;
using EPiServer.Framework.Initialization;
using EPiServer.ServiceLocation;
using System.Reflection;
// type and static void method 'Init' to assign GetAssembliesToScan or GetRegistrationSorter
[assembly: System.Web.PreApplicationStartMethod(typeof(Example.StartupClass), nameof(Example.StartupClass.Init))]
namespace Example
{
/// <summary>
/// Note: this is an optional example of how to scan custom assemblies or use a different IRegistrationSorter.
/// </summary>
public class StartupClass
{
/// <summary>
/// Run pre start code
/// </summary>
public static void Init()
{
InitializeDotNetStarterRegistrations.ModuleEnabled = false;
}
}
/// <summary>
/// Example customization for advanced usages
/// </summary>
[InitializableModule]
public class CustomDotNetStarterRegistration : IConfigurableModule
{
void IConfigurableModule.ConfigureContainer(ServiceConfigurationContext context)
{
var customAssemblies = new Assembly[]
{
typeof(Example.StartupClass).Assembly // look for types in StartupClass assembly
// can add many more assemblies in this manner
};
context.Services.AddDotNetStarterRegistrations
(
assembliesToScan: customAssemblies
);
}
void IInitializableModule.Initialize(InitializationEngine context) { }
void IInitializableModule.Uninitialize(InitializationEngine context) { }
}
}
Example Service
To create an injectable service in a project or NuGet package, add a reference to DotNetStarter.RegistrationAbstractions. Then create a service abstraction, example below:
using DotNetStarter.Abstractions;
namespace ExampleNamespace
{
public interface IAwesomeService
{
void DoAwesomeThing();
}
// this attribute marks AwsomeServiceImplementation as an implementation of IAwesomeService for dependency inject.
[Registration(typeof(IAwesomeService), Lifecycle.Singleton)]
public class AwsomeServiceImplementation : IAwesomeService
{
public void DoAwesomeThing()
{
// where awesome things happen
}
}
}
Important: The following assembly attributes must be added to the project code, normally in the Properties\AssemblyInfo.cs file where other assembly level information is stored. These attributes are used during the scanning process to determine which DLL files to examine for discovering RegistrationAttribute usages.
using DotNetStarter.Abstractions;
// this assembly attribute instructs the default assembly loaders to only get ones with this attribute
[assembly: DiscoverableAssembly]
// this assembly attribute instructs the type scanning to only look in exported types within the assembly instead of all types
// this will improve performance over using ExportsType.All
[assembly: Exports(ExportsType.ExportsOnly)]
Example Project
A short example project is also provided in the source code which targets multiple frameworks, demonstrated in the csproj file.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 was computed. 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 | netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard1.6 is compatible. netstandard2.0 was computed. netstandard2.1 was computed. |
.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 | tizen30 was computed. 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 1.6
- DotNetStarter.RegistrationAbstractions (>= 1.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.0.0)
- Microsoft.Extensions.DependencyModel (>= 1.1.0)
- NETStandard.Library (>= 1.6.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Initial release.