public override void RegisterInstance(object instance, RegistrationOptions options) { if (instance == null) { throw new ArgumentNullException(nameof(instance)); } if (!options.AsTypes.Any()) { options.As(instance.GetType()); } var instanceType = instance.GetType().GetTypeInfo(); foreach (var asType in options.AsTypes) { if (!asType.GetTypeInfo().IsAssignableFrom(instanceType)) { throw new InvalidOperationException($"Type {instanceType.AsType()} is not assignable to {asType}"); } _items.AddOrUpdate(asType, _ => instance, (_, __) => instance); } if (!options.IsExternallyOwned) { EnlistDisposable(instance); } }
public DependencyDescriptor(Type type, Func <IDependencyResolver, object> resolveFn, RegistrationOptions registration, InstanceScope scope, bool instantResolution) { Type = type; ResolveFn = resolveFn; Registration = registration; if (!registration.AsTypes.Any()) { registration.As(type); } Scope = scope; InstantResolution = instantResolution; }