Exemple #1
0
 public static void Add <T>(this IPlasmaContainer container, Type type, Lazy <T> instanceFactory)
 {
     if (container == null)
     {
         throw new ArgumentNullException("container");
     }
     container.Add(type, CreateLazy(instanceFactory));
 }
Exemple #2
0
 public static void Add(this IPlasmaContainer container, Type type, object instance)
 {
     if (container == null)
     {
         throw new ArgumentNullException("container");
     }
     container.Add(type, CreateLazy(instance));
 }
Exemple #3
0
 /// <summary>
 /// Register service with default factory
 /// </summary>
 /// <typeparam name="T">Registering type, e.g. IMyService</typeparam>
 /// <typeparam name="TImpl">Service implementation, e.g. MyServiceImpl</typeparam>
 /// <param name="container"></param>
 public static void Add <T, TImpl>(this IPlasmaContainer container)
 {
     if (container == null)
     {
         throw new ArgumentNullException("container");
     }
     container.Add(typeof(T), typeof(TImpl));
 }
Exemple #4
0
 /// <summary>
 /// Register service lazy
 /// </summary>
 /// <typeparam name="T">Registering type, e.g. IMyService</typeparam>
 /// <param name="container"></param>
 /// <param name="instanceFactory">Service lazy instance</param>
 public static void Add <T>(this IPlasmaContainer container, Lazy <T> instanceFactory)
 {
     if (container == null)
     {
         throw new ArgumentNullException("container");
     }
     // TODO Eliminate lazy double wrapping: Lazy<T>(Lazy<object>(Lazy<T>()))
     container.Add(typeof(T), CreateLazy(instanceFactory));
 }
Exemple #5
0
    /// <summary>
    /// Try get service of registered type or register by factory
    /// </summary>
    public static T Get <T>(this IPlasmaContainer container, Func <T> factory)
    {
        if (container == null)
        {
            throw new ArgumentNullException("container");
        }
        if (factory == null)
        {
            throw new ArgumentNullException("factory");
        }
        var result = container.TryGet <T>();

        if (ReferenceEquals(null, result))
        {
            result = factory();
            container.Add(result);
        }
        return(result);
    }
Exemple #6
0
 public void Should_allow_register_func_factory_by_iface_and_lambda()
 {
     _sut.Add <IMyService>(() => new MyService());
     Verify();
 }