DotNetStarter.Extensions.Registrations.EpiserverCms 0.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DotNetStarter.Extensions.Registrations.EpiserverCms --version 0.1.0
NuGet\Install-Package DotNetStarter.Extensions.Registrations.EpiserverCms -Version 0.1.0
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="DotNetStarter.Extensions.Registrations.EpiserverCms" Version="0.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNetStarter.Extensions.Registrations.EpiserverCms --version 0.1.0
#r "nuget: DotNetStarter.Extensions.Registrations.EpiserverCms, 0.1.0"
#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 DotNetStarter.Extensions.Registrations.EpiserverCms as a Cake Addin
#addin nuget:?package=DotNetStarter.Extensions.Registrations.EpiserverCms&version=0.1.0

// Install DotNetStarter.Extensions.Registrations.EpiserverCms as a Cake Tool
#tool nuget:?package=DotNetStarter.Extensions.Registrations.EpiserverCms&version=0.1.0

DotNetStarter.Extensions.Registrations Read Me

Build status

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 Compatible and additional computed target framework versions.
.NET Framework net461 is compatible.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.1.0 1,249 7/23/2018
1.0.0 1,273 4/2/2018
0.1.0 1,174 3/27/2018

Initial release.