Bootstrap Library overview

andyb1979 edited this page Nov 7, 2018 · 6 revisions

The SciChart.UI.Bootstrap library provides a bootstrapper class which automatically discovers & registers types with a Unity Container, depending on attributes and various flags.

Can be used in client or server applications (including .NET Core, .NET Framework), and has no dependency on WPF or UWP assemblies.

NuGet Package

Dependencies for SciChart.UI.Bootstrap

  • Log4Net 2.0.8
  • Unity 5.8.11

Key Types Included in SciChart.UI.Bootstrap

ExportTypeAttribute

An attribute used to decorate classes to denote them for automatic registration with the Unity Container.

Some examples

public interface IFoo
{
}

// This type is automatically registered with the Unity Container 
// Every time IFoo is resolved, you get a new instance
[ExportType(typeof(IFoo))]
public class Foo : IFoo
{
	// Any other reigstered dependency can go in the constructor
	public Foo(IUnityContainer container)
	{
	}
}

public interface IBar
{
}

// This type is automatically registered as a Singleton with the Unity Container 
// Every time IBar is resolved, you get the same instance 
[ExportType(typeof(IBar), CreateAs.Singleton)]
public class Bar : IBar
{
	// Any other reigstered dependency can go in the constructor
	public Bar(IUnityContainer container)
	{
	}
}

public interface IFooBar
{
}

// This type is automatically registered as a Singleton and resolved by name 
// Every time IFooBar is resolved with name="FooBar", 
// e.g. container.Resolve<IFooBar>("FooBar") 
// you get the same instance 
[ExportType(typeof(IFooBar), CreateAs.Singleton, DataMode.Any, "FooBar")]
public class Foobar : IFooBar
{
	// Any other reigstered dependency can go in the constructor
	public Foobar(IUnityContainer container)
	{
	}
}

AbtBootstrapper

A bootstrapper class which can be used to discover types in your application to register with the Unity Container, decovered with the [ExportType] attribute.

Usage

    public partial class App : Application
    {
        private AbtBootstrapper _bootstrapper;

        public App()
        {
            var container = new UnityContainer();
            _bootstrapper = new AbtBootstrapper(container, new AttributedTypeDiscoveryService(new AutoAssemblyDiscovery()));
            _bootstrapper.Initialize();

             // At this point, your container now contains all the types decorated with [ExportType] attribute
             // You may resolve them as normal in Unity 
             var foo = container.Resolve<IFoo>();
        }
    }

AttributedTypeDiscoveryService

A type of discovery service which searches for types decorated with the [ExportType] attribute for registration with the Unity Container.

AutoAssemblyDiscovery

A type of discovery service which automatically searches for assemblies, scanning the output directory and registering with the Unity Container.

All assemblies are scanned and you can exclude some for faster startup by passing in the params string[] asmsToExclude to the constructor.

ExplicitAssemblyDiscovery

A type of discovery service which allows explicit listing of assemblies to scan for the [ExportType] attribute & for registering with the Unity Container.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.