// Author: Gockner, Simon // Created: 2019-11-22 // Copyright(c) 2019 SimonG. All Rights Reserved. using System; using LightweightIocContainer.Interfaces; using LightweightIocContainer.Interfaces.Registrations; namespace LightweightIocContainer.Registrations { /// /// The to register either only an interface or only a /// /// The of the internal class SingleTypeRegistration : RegistrationBase, ISingleTypeRegistration { /// /// The to register either only an interface or only a /// /// The of the interface or /// The of the /// The current instance of the public SingleTypeRegistration(Type interfaceType, Lifestyle lifestyle, IocContainer container) : base(interfaceType, lifestyle, container) { } /// /// that is invoked instead of creating an instance of this the default way /// public Func? FactoryMethod { get; private set; } /// /// Pass a that will be invoked instead of creating an instance of this the default way /// /// The /// The current instance of this public ISingleTypeRegistration WithFactoryMethod(Func factoryMethod) { FactoryMethod = factoryMethod; return this; } public override bool Equals(object? obj) { if (obj is not SingleTypeRegistration singleTypeRegistration) return false; if (FactoryMethod == null && singleTypeRegistration.FactoryMethod != null) return false; if (FactoryMethod != null && singleTypeRegistration.FactoryMethod == null) return false; return base.Equals(obj); } public override int GetHashCode() => base.GetHashCode(); } }