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)); }
public static void Add(this IPlasmaContainer container, Type type, object instance) { if (container == null) { throw new ArgumentNullException("container"); } container.Add(type, CreateLazy(instance)); }
/// <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)); }
public void Init() { // Setup _sut = new PlasmaContainer() { ReflectionPermission = ReflectionPermission.Allow }; Instantiated = 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)); }
internal static object Create(IPlasmaContainer container, Type type) { Func <IPlasmaContainer, object> factory; if (_factories.TryGetValue(type, out factory)) { return(factory(container)); } return(null); }
/// <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); }
/// <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); }
static partial void Init(IPlasmaContainer c) { PlasmaRegistration.Run(); }
public static void InitContainer(IPlasmaContainer c) { Init(c); }
static partial void Init(IPlasmaContainer c);
public MyServiceWithScope(IPlasmaContainer container) { _service = container.Get<IMyService>(); }
/*+ * static object ref1 = typeof(MovieFinder); */ public static void RegisterAll(IPlasmaContainer c) { /*# RegisterAll */ }
public void BaseContainerInit() { // empty container _sut = new PlasmaContainer(); _AssemblyInit.InitContainer(_sut); }