/// <summary> /// Register some assembly, by registering all type they export that are marked with <see cref="ExportAttribute"/>. /// </summary> public void RegisterAssemblies <T>(IEnumerable <Assembly> assemblies) where T : Attribute { foreach (var t in assemblies.Where(x => x != null).SelectMany(x => x.GetLoadableTypes())) { try { var ea = t.GetCustomAttributes <T>(false); foreach (var export in ea) { if (!TypeTreeActivation.CanBeInstantiated(t)) { Log.Warning(this, $"[Registry]: Type {t.Name} can't be exported, it is not Resolvable."); continue; } Register(t); break; // register only once } } catch (TypeLoadException) { } } }
/// <summary> /// Create that object from scratch regardless of registration /// </summary> /// <param name="type">The type to instantiate.</param> /// <returns>A newly created instance</returns> /// <exception cref="InvalidOperationException">If no appropriate constructor can be found.</exception> public object Create(Type type, params object[] parameters) { EnsureAlive(); return(TypeTreeActivation.Create(services, scope, type, parameters)); }
/// <summary> /// Whether given type can be created. Basically it must be a concrete class with some constructors /// with arguments that can also be created (or resolved). /// </summary> /// <param name="type">The type to check for creation.</param> /// <returns>Whether the type can be instantiated</returns> public bool CanCreate(Type type) { EnsureAlive(); return(TypeTreeActivation.CanCreate(services, scope, type)); }
public IEnumerable <object> ResolveAll(Predicate <Type> matching) { EnsureAlive(); return(TypeTreeActivation.Resolve(services, scope, matching)); }
public IEnumerable <object> ResolveAll(Type type) { EnsureAlive(); return(TypeTreeActivation.Resolve(services, scope, type)); }
public object Resolve(Type type) { EnsureAlive(); return(TypeTreeActivation.ResolveSingle(services, scope, type)); }
public void ResolveProperties(object instance) { EnsureAlive(); TypeTreeActivation.ResolveProperties(services, scope, instance); }
/// <summary> /// Register an instance as an instance of a given type. It will returned when resolving any /// base class or implemented interface. /// </summary> /// <param name="facade">The type that is registered.</param> /// <param name="instance">The instance for this type. If null it will be created on demand /// on the first access to <paramref name="facade"/></param> public void Register(Type facade, object instance) { EnsureAlive(); TypeTreeActivation.Register(services, facade, instance); }