Example #1
0
 public DiCachedRootBinding(IDiRootBinding binding, DiRootBindingType rootBindingType)
 {
     if (binding == null)
     {
         throw new ArgumentNullException(nameof(binding));
     }
     this.binding         = binding;
     this.rootBindingType = rootBindingType;
 }
Example #2
0
        public IDiRootBinding GetRootBinding(DiRootBindingType requestedRootBindingType)
        {
            if (requestedRootBindingType != rootBindingType)
            {
                throw new InvalidOperationException($"Trying to use a '{rootBindingType}' binding as a '{requestedRootBindingType}' binding");
            }
            var bindingLoc = binding;

            if (bindingLoc == null)
            {
                throw new InvalidOperationException("Trying to bind after an instance had already been created.");
            }
            return(bindingLoc);
        }
Example #3
0
 private object InternalInstantiate(Type type, DiRootBindingType rootBindingType) =>
 GetOrAddCachedBinding(type, rootBindingType).Instantiate(this);
Example #4
0
 private IDiCachedRootBinding GetOrAddCachedBinding(Type type, DiRootBindingType rootBindingType)
 {
     return(cachedBindings.GetOrAdd(type, t => new DiCachedRootBinding(new DiRootBinding(t), rootBindingType)));
 }
Example #5
0
 private object InternalGet(Type type, DiRootBindingType rootBindingType) =>
 GetOrAddCachedBinding(type, rootBindingType).GetResult(this);
Example #6
0
 public IDiRootBinding GetRootBinding(Type type, DiRootBindingType rootBindingType) =>
 GetOrAddCachedBinding(type, rootBindingType).GetRootBinding(rootBindingType);
Example #7
0
 private DiFluentBinderCommon <object> InternalBind(Type type, DiRootBindingType rootBindingType) =>
 new DiFluentBinderCommon <object>(this, GetRootBinding(type, rootBindingType));
Example #8
0
 private DiFluentBinderCommon <T> InternalBind <T>(DiRootBindingType rootBindingType) =>
 new DiFluentBinderCommon <T>(this, GetRootBinding(typeof(T), rootBindingType));
Example #9
0
 private IEnumerable <IDiRootBindingItem> GetGenericItems(IDiContainer di, DiRootBindingType rootBindingType)
 {
     return(abstractType.IsGenericType
         ? di.GetRootBinding(abstractType.GetGenericTypeDefinition(), rootBindingType).Items
         : Enumerable.Empty <IDiRootBindingItem>());
 }