예제 #1
0
        internal object GetInstance(Type type, bool throwable = true)
        {
            var injectionModel = InjectionModels.FirstOrDefault(model => model.Type == type || model.ReferencedType == type);

            switch (injectionModel?.InjectionMode)
            {
            case SpeckType.PerRequest:
                var newSpeck = Activator.CreateInstance(injectionModel.Type);
                return(newSpeck);

            case SpeckType.Singleton:
                return(injectionModel.Instance);

            default:
                if (throwable)
                {
                    throw new Exception($"Type: {type.Name} not injected");
                }
                else
                {
                    return(null);
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Looks to see if Specky has the speck type injected.  Useful to prevent initializing specks of type PerRequest
 /// </summary>
 /// <param name="type">Speck Type to look up</param>
 /// <returns></returns>
 public bool HasSpeck(Type type)
 {
     return(InjectionModels.FirstOrDefault(model => model.Type == type || model.ReferencedType == type) != null);
 }