diff --git a/src/stashbox.tests/DecoratorTests.cs b/src/stashbox.tests/DecoratorTests.cs index 9c8f1dcb..7a9473f6 100644 --- a/src/stashbox.tests/DecoratorTests.cs +++ b/src/stashbox.tests/DecoratorTests.cs @@ -481,6 +481,19 @@ public void DecoratorTests_RemapDecorator_V2() } } + [TestMethod] + public void DecoratorTests_Service_ImplementationType() + { + using (var container = new StashboxContainer()) + { + container.RegisterDecorator(context => + { + Assert.AreEqual(typeof(ITest1), context.ServiceType); + Assert.AreEqual(typeof(TestDecorator1), context.ImplementationType); + }); + } + } + public interface ITest1 { ITest1 Test { get; } } public interface IDecoratorDep { } diff --git a/src/stashbox.tests/WireUpTests.cs b/src/stashbox.tests/WireUpTests.cs index 98458d40..033026a0 100644 --- a/src/stashbox.tests/WireUpTests.cs +++ b/src/stashbox.tests/WireUpTests.cs @@ -79,7 +79,7 @@ public void InjectionMemberTests_WireUp_WithoutService() { container.RegisterType(); var test1 = new Test1(); - container.WireUpAs(test1); + container.WireUp(test1); var inst = container.Resolve(); Assert.IsNotNull(inst); diff --git a/src/stashbox/Infrastructure/IDependencyRegistrator.cs b/src/stashbox/Infrastructure/IDependencyRegistrator.cs index 6c6fdd71..5225ed71 100644 --- a/src/stashbox/Infrastructure/IDependencyRegistrator.cs +++ b/src/stashbox/Infrastructure/IDependencyRegistrator.cs @@ -104,6 +104,15 @@ IDependencyRegistrator RegisterType(Action confi /// The which on this method was called. IDependencyRegistrator WireUp(Type serviceType, object instance, object name = null, bool withoutDisposalTracking = false); + /// + /// Registers an already constructed instance, but the container will perform injections and extensions on it. + /// + /// The constructed object. + /// The name of the registration. + /// If it's set to true the container will exclude the instance from the disposal tracking. + /// The which on this method was called. + IDependencyRegistrator WireUp(object instance, object name = null, bool withoutDisposalTracking = false); + /// /// Registers a type with singleton lifetime. /// diff --git a/src/stashbox/Infrastructure/Registration/IBaseFluentRegistrator.cs b/src/stashbox/Infrastructure/Registration/IBaseFluentRegistrator.cs index d8df447a..f8486742 100644 --- a/src/stashbox/Infrastructure/Registration/IBaseFluentRegistrator.cs +++ b/src/stashbox/Infrastructure/Registration/IBaseFluentRegistrator.cs @@ -11,6 +11,16 @@ namespace Stashbox.Infrastructure.Registration /// public interface IBaseFluentRegistrator { + /// + /// The service type. + /// + Type ServiceType { get; } + + /// + /// The implementation type. + /// + Type ImplementationType { get; } + /// /// Sets injection parameters for the registration. /// diff --git a/src/stashbox/Infrastructure/Registration/IFluentServiceRegistrator.cs b/src/stashbox/Infrastructure/Registration/IFluentServiceRegistrator.cs index 211a88b8..bb46923d 100644 --- a/src/stashbox/Infrastructure/Registration/IFluentServiceRegistrator.cs +++ b/src/stashbox/Infrastructure/Registration/IFluentServiceRegistrator.cs @@ -8,16 +8,6 @@ namespace Stashbox.Infrastructure.Registration /// public interface IFluentServiceRegistrator : IBaseFluentRegistrator { - /// - /// The service type. - /// - Type ServiceType { get; } - - /// - /// The implementation type. - /// - Type ImplementationType { get; } - /// /// Sets the lifetime of the registration. /// diff --git a/src/stashbox/Registration/DecoratorRegistrationContext.cs b/src/stashbox/Registration/DecoratorRegistrationContext.cs index 40f9764f..e71d7e7c 100644 --- a/src/stashbox/Registration/DecoratorRegistrationContext.cs +++ b/src/stashbox/Registration/DecoratorRegistrationContext.cs @@ -13,12 +13,20 @@ internal class DecoratorRegistrationContext : IDecoratorRegistrationContext private readonly IServiceRegistrator serviceRegistrator; private bool replaceExistingRegistration; + public Type ServiceType => this.registrationContext.ServiceType; + + public Type ImplementationType => this.registrationContext.ImplementationType; + public DecoratorRegistrationContext(RegistrationContext registrationContext, IServiceRegistrator serviceRegistrator) { this.registrationContext = registrationContext; this.serviceRegistrator = serviceRegistrator; } + public IStashboxContainer Register() => this.serviceRegistrator.Register(this.registrationContext, true, this.replaceExistingRegistration); + + public IStashboxContainer ReMap() => this.serviceRegistrator.ReMap(this.registrationContext, true); + public IFluentDecoratorRegistrator WithInjectionParameters(params InjectionParameter[] injectionParameters) { this.registrationContext.WithInjectionParameters(injectionParameters); @@ -44,10 +52,6 @@ public IFluentDecoratorRegistrator WithoutDisposalTracking() return this; } - public IStashboxContainer Register() => this.serviceRegistrator.Register(this.registrationContext, true, this.replaceExistingRegistration); - - public IStashboxContainer ReMap() => this.serviceRegistrator.ReMap(this.registrationContext, true); - public IFluentDecoratorRegistrator ReplaceExisting() { this.replaceExistingRegistration = true; diff --git a/src/stashbox/StashboxContainer.Registrator.cs b/src/stashbox/StashboxContainer.Registrator.cs index 6631741d..32bf2387 100644 --- a/src/stashbox/StashboxContainer.Registrator.cs +++ b/src/stashbox/StashboxContainer.Registrator.cs @@ -67,6 +67,10 @@ public IDependencyRegistrator RegisterInstance(Type serviceType, object instance public IDependencyRegistrator WireUpAs(TFrom instance, object name = null, bool withoutDisposalTracking = false) => this.WireUp(typeof(TFrom), instance, name, withoutDisposalTracking); + /// + public IDependencyRegistrator WireUp(object instance, object name = null, bool withoutDisposalTracking = false) => + this.WireUp(instance.GetType(), instance, name, withoutDisposalTracking); + /// public IDependencyRegistrator WireUp(Type serviceType, object instance, object name = null, bool withoutDisposalTracking = false) {