public void ServiceEquality(Type dependencyType, object ownedKey, Type ownedType, bool expected) { var dependencyService = new TypedService(dependencyType); var instancePerOwnedKey = new InstancePerOwnedKey(dependencyService); var ownedService = ownedKey != null ? (IServiceWithType) new KeyedService(ownedKey, ownedType) : new TypedService(ownedType); Assert.Equal(expected, instancePerOwnedKey.Equals(ownedService)); }
/// <summary> /// Configure the component so that every dependent component or call to Resolve() /// within a ILifetimeScope created by an owned instance gets the same, shared instance. /// Dependent components in lifetime scopes that are children of the owned instance scope will /// share the parent's instance. If no appropriate owned instance scope can be found in the /// hierarchy an <see cref="DependencyResolutionException"/> is thrown. /// </summary> /// <param name="serviceType">The service type provided by the component.</param> /// <returns>A registration builder allowing further configuration of the component.</returns> public IRegistrationBuilder <TLimit, TActivatorData, TRegistrationStyle> InstancePerOwned(Type serviceType) { var key = new InstancePerOwnedKey(new TypedService(serviceType)); return(InstancePerMatchingLifetimeScope(key)); }