public object Create(Type type, BuildContext context, IEnumerable <InjectableMember> injectableMembers = null) { var instance = inner.Create(type, context, injectableMembers); if (instance == null) { if (typeLocator.TryLocate(type, out instance)) { return(instance); } throw new Exception($"Cannot create instance of type {type}"); } return(instance); }
public CreationResult Create(Type type, CreationHints creationHints = null) { if (locator.TryLocate(type, out var instance)) { var layout = instance as Layout; if (layout != null) { ObserveSelector(layout); } return(new CreationResult(instance, new CreationHints())); } try { var creationResult = new CreationResult(Activator.CreateInstance(type), new CreationHints()); return(creationResult); } catch (Exception e) { throw new TypeInitializationException($"Cannot create instance of type {type}: The dependency injection container could not create it and it doesn't have a default constructor. Please verify that all its dependencies have been registered with the resolver.", e); } }