private object FallbackResolve(Type type) { return(_dependencyFactory.FallbackBehavior switch { FallbackResolveBehavior.ThrowException => throw new InvalidOperationException($"No suitable registration has been found to resolve type {type}.{Environment.NewLine}Available registrations:{Environment.NewLine}{Environment.NewLine}{DumpSlots(this)}"), _ => EnlistDisposable(DependencyDescriptor.FindConstructor(type).Invoke(this)) });
private bool IsInheritable(DependencyDescriptor descriptor) { if (!descriptor.Scope.LifetimeScopeRestriction?.Equals(_scope) ?? false) { return(true); } return(!descriptor.Scope.IsSharedWithNestedScopes); }
private void InitializeSlots(DependencyDescriptor descriptor) { if (!IsValidScope(descriptor)) { return; } var slot = new Slot(Interlocked.Increment(ref _slotIdRef), descriptor); foreach (var type in slot.Descriptor.Registration.AsTypes) { if (!type.IsAssignableFrom(descriptor.Type)) { throw new InvalidOperationException($"Type {descriptor.Type} is not assignable to {type}"); } _slots[type] = slot; } }
public void RegisterType <T>(InstanceScope scope, Action <RegistrationOptions> options = null) { Register(typeof(T), DependencyDescriptor.FindConstructor(typeof(T)), options, scope, false); }
private bool IsValidScope(DependencyDescriptor descriptor) { return(descriptor.Scope.LifetimeScopeRestriction?.Equals(_scope) ?? true); }
public Slot(int id, DependencyDescriptor descriptor) { Id = id; Descriptor = descriptor; }