Beispiel #1
0
 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))
     });
Beispiel #2
0
 private bool IsInheritable(DependencyDescriptor descriptor)
 {
     if (!descriptor.Scope.LifetimeScopeRestriction?.Equals(_scope) ?? false)
     {
         return(true);
     }
     return(!descriptor.Scope.IsSharedWithNestedScopes);
 }
Beispiel #3
0
        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;
            }
        }
Beispiel #4
0
 public void RegisterType <T>(InstanceScope scope, Action <RegistrationOptions> options = null)
 {
     Register(typeof(T), DependencyDescriptor.FindConstructor(typeof(T)), options, scope, false);
 }
Beispiel #5
0
 private bool IsValidScope(DependencyDescriptor descriptor)
 {
     return(descriptor.Scope.LifetimeScopeRestriction?.Equals(_scope) ?? true);
 }
Beispiel #6
0
 public Slot(int id, DependencyDescriptor descriptor)
 {
     Id         = id;
     Descriptor = descriptor;
 }