2018-06-16 13:13:29 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using LightInject;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Composing.LightInject
|
|
|
|
|
|
{
|
2018-06-29 13:17:46 +02:00
|
|
|
|
/// <summary>
|
2018-07-06 18:52:23 +02:00
|
|
|
|
/// Implements <see cref="IContainer"/> with LightInject.
|
2018-06-29 13:17:46 +02:00
|
|
|
|
/// </summary>
|
2018-07-06 18:52:23 +02:00
|
|
|
|
public class LightInjectContainer : IContainer
|
2018-06-16 13:13:29 +02:00
|
|
|
|
{
|
2018-06-29 13:17:46 +02:00
|
|
|
|
private readonly IServiceContainer _container;
|
2018-06-16 13:13:29 +02:00
|
|
|
|
|
2018-06-29 13:17:46 +02:00
|
|
|
|
/// <summary>
|
2018-07-06 18:52:23 +02:00
|
|
|
|
/// Initializes a new instance of the <see cref="LightInjectContainer"/> with a LightInject container.
|
2018-06-29 13:17:46 +02:00
|
|
|
|
/// </summary>
|
2018-07-06 18:52:23 +02:00
|
|
|
|
public LightInjectContainer(IServiceContainer container)
|
2018-06-16 13:13:29 +02:00
|
|
|
|
{
|
2018-06-29 13:17:46 +02:00
|
|
|
|
_container = container;
|
2018-06-16 13:13:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-06 18:52:23 +02:00
|
|
|
|
/// <inheritdoc />
|
2018-06-29 13:17:46 +02:00
|
|
|
|
public object ConcreteContainer => _container;
|
|
|
|
|
|
|
2018-07-20 09:49:05 +02:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public object GetInstance(Type type)
|
|
|
|
|
|
=> _container.GetInstance(type);
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public object GetInstance(Type type, object[] args)
|
|
|
|
|
|
=> _container.GetInstance(type, args);
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public object TryGetInstance(Type type)
|
|
|
|
|
|
=> _container.TryGetInstance(type);
|
|
|
|
|
|
|
2018-06-29 13:17:46 +02:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public void RegisterSingleton<T>(Func<IContainer, T> factory)
|
|
|
|
|
|
=> _container.RegisterSingleton(f => factory(this));
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2018-06-16 13:13:29 +02:00
|
|
|
|
public void Register<T>(Func<IContainer, T> factory)
|
2018-06-29 13:17:46 +02:00
|
|
|
|
=> _container.Register(f => factory(this));
|
2018-06-16 13:13:29 +02:00
|
|
|
|
|
2018-06-29 13:17:46 +02:00
|
|
|
|
/// <inheritdoc />
|
2018-06-28 22:38:14 +02:00
|
|
|
|
public void Register<T, TService>(Func<IContainer, T, TService> factory)
|
2018-06-29 13:17:46 +02:00
|
|
|
|
=> _container.Register<T, TService>((f, x) => factory(this, x));
|
2018-06-28 22:38:14 +02:00
|
|
|
|
|
2018-06-29 13:17:46 +02:00
|
|
|
|
/// <inheritdoc />
|
2018-06-16 13:13:29 +02:00
|
|
|
|
public T RegisterCollectionBuilder<T>()
|
2018-06-29 13:17:46 +02:00
|
|
|
|
=> _container.RegisterCollectionBuilder<T>();
|
2018-06-16 13:13:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|