Esempio n. 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));
 }
Esempio n. 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));
 }
Esempio n. 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));
 }
Esempio n. 4
0
 public void Init()
 {
     // Setup
     _sut = new PlasmaContainer()
     {
         ReflectionPermission = ReflectionPermission.Allow
     };
     Instantiated = 0;
 }
Esempio n. 5
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));
 }
Esempio n. 6
0
        internal static object Create(IPlasmaContainer container, Type type)
        {
            Func <IPlasmaContainer, object> factory;

            if (_factories.TryGetValue(type, out factory))
            {
                return(factory(container));
            }
            return(null);
        }
Esempio n. 7
0
        /// <summary>
        /// Inject dependencies from container
        /// </summary>
        internal static bool TryPlumb(object instance, IPlasmaContainer c)
        {
            Action <IPlasmaContainer, object> act;

            if (_plumbers.TryGetValue(instance.GetType(), out act))
            {
                act(c, instance);
                return(true);
            }
            return(false);
        }
Esempio n. 8
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);
    }
Esempio n. 9
0
 static partial void Init(IPlasmaContainer c)
 {
     PlasmaRegistration.Run();
 }
Esempio n. 10
0
 public static void InitContainer(IPlasmaContainer c)
 {
     Init(c);
 }
Esempio n. 11
0
 static partial void Init(IPlasmaContainer c);
Esempio n. 12
0
			public MyServiceWithScope(IPlasmaContainer container)
			{
				_service = container.Get<IMyService>();
			}
Esempio n. 13
0
        /*+
         * static object ref1 = typeof(MovieFinder);
         */

        public static void RegisterAll(IPlasmaContainer c)
        {
            /*# RegisterAll */
        }
Esempio n. 14
0
 public void BaseContainerInit()
 {
     // empty container
     _sut = new PlasmaContainer();
     _AssemblyInit.InitContainer(_sut);
 }