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