Skip to content

Commit 93618e7

Browse files
author
Peter Csajtai
committed
Refactor
1 parent 205ebac commit 93618e7

File tree

7 files changed

+45
-15
lines changed

7 files changed

+45
-15
lines changed

src/stashbox.tests/DecoratorTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,19 @@ public void DecoratorTests_RemapDecorator_V2()
481481
}
482482
}
483483

484+
[TestMethod]
485+
public void DecoratorTests_Service_ImplementationType()
486+
{
487+
using (var container = new StashboxContainer())
488+
{
489+
container.RegisterDecorator<ITest1, TestDecorator1>(context =>
490+
{
491+
Assert.AreEqual(typeof(ITest1), context.ServiceType);
492+
Assert.AreEqual(typeof(TestDecorator1), context.ImplementationType);
493+
});
494+
}
495+
}
496+
484497
public interface ITest1 { ITest1 Test { get; } }
485498

486499
public interface IDecoratorDep { }

src/stashbox.tests/WireUpTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void InjectionMemberTests_WireUp_WithoutService()
7979
{
8080
container.RegisterType<ITest, Test>();
8181
var test1 = new Test1();
82-
container.WireUpAs(test1);
82+
container.WireUp(test1);
8383
var inst = container.Resolve<Test1>();
8484

8585
Assert.IsNotNull(inst);

src/stashbox/Infrastructure/IDependencyRegistrator.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ IDependencyRegistrator RegisterType<TTo>(Action<IFluentServiceRegistrator> confi
104104
/// <returns>The <see cref="IDependencyRegistrator"/> which on this method was called.</returns>
105105
IDependencyRegistrator WireUp(Type serviceType, object instance, object name = null, bool withoutDisposalTracking = false);
106106

107+
/// <summary>
108+
/// Registers an already constructed instance, but the container will perform injections and extensions on it.
109+
/// </summary>
110+
/// <param name="instance">The constructed object.</param>
111+
/// <param name="name">The name of the registration.</param>
112+
/// <param name="withoutDisposalTracking">If it's set to true the container will exclude the instance from the disposal tracking.</param>
113+
/// <returns>The <see cref="IDependencyRegistrator"/> which on this method was called.</returns>
114+
IDependencyRegistrator WireUp(object instance, object name = null, bool withoutDisposalTracking = false);
115+
107116
/// <summary>
108117
/// Registers a type with singleton lifetime.
109118
/// </summary>

src/stashbox/Infrastructure/Registration/IBaseFluentRegistrator.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ namespace Stashbox.Infrastructure.Registration
1111
/// </summary>
1212
public interface IBaseFluentRegistrator<out TFluentRegistrator>
1313
{
14+
/// <summary>
15+
/// The service type.
16+
/// </summary>
17+
Type ServiceType { get; }
18+
19+
/// <summary>
20+
/// The implementation type.
21+
/// </summary>
22+
Type ImplementationType { get; }
23+
1424
/// <summary>
1525
/// Sets injection parameters for the registration.
1626
/// </summary>

src/stashbox/Infrastructure/Registration/IFluentServiceRegistrator.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@ namespace Stashbox.Infrastructure.Registration
88
/// </summary>
99
public interface IFluentServiceRegistrator : IBaseFluentRegistrator<IFluentServiceRegistrator>
1010
{
11-
/// <summary>
12-
/// The service type.
13-
/// </summary>
14-
Type ServiceType { get; }
15-
16-
/// <summary>
17-
/// The implementation type.
18-
/// </summary>
19-
Type ImplementationType { get; }
20-
2111
/// <summary>
2212
/// Sets the lifetime of the registration.
2313
/// </summary>

src/stashbox/Registration/DecoratorRegistrationContext.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,20 @@ internal class DecoratorRegistrationContext : IDecoratorRegistrationContext
1313
private readonly IServiceRegistrator serviceRegistrator;
1414
private bool replaceExistingRegistration;
1515

16+
public Type ServiceType => this.registrationContext.ServiceType;
17+
18+
public Type ImplementationType => this.registrationContext.ImplementationType;
19+
1620
public DecoratorRegistrationContext(RegistrationContext registrationContext, IServiceRegistrator serviceRegistrator)
1721
{
1822
this.registrationContext = registrationContext;
1923
this.serviceRegistrator = serviceRegistrator;
2024
}
2125

26+
public IStashboxContainer Register() => this.serviceRegistrator.Register(this.registrationContext, true, this.replaceExistingRegistration);
27+
28+
public IStashboxContainer ReMap() => this.serviceRegistrator.ReMap(this.registrationContext, true);
29+
2230
public IFluentDecoratorRegistrator WithInjectionParameters(params InjectionParameter[] injectionParameters)
2331
{
2432
this.registrationContext.WithInjectionParameters(injectionParameters);
@@ -44,10 +52,6 @@ public IFluentDecoratorRegistrator WithoutDisposalTracking()
4452
return this;
4553
}
4654

47-
public IStashboxContainer Register() => this.serviceRegistrator.Register(this.registrationContext, true, this.replaceExistingRegistration);
48-
49-
public IStashboxContainer ReMap() => this.serviceRegistrator.ReMap(this.registrationContext, true);
50-
5155
public IFluentDecoratorRegistrator ReplaceExisting()
5256
{
5357
this.replaceExistingRegistration = true;

src/stashbox/StashboxContainer.Registrator.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ public IDependencyRegistrator RegisterInstance(Type serviceType, object instance
6767
public IDependencyRegistrator WireUpAs<TFrom>(TFrom instance, object name = null, bool withoutDisposalTracking = false) =>
6868
this.WireUp(typeof(TFrom), instance, name, withoutDisposalTracking);
6969

70+
/// <inheritdoc />
71+
public IDependencyRegistrator WireUp(object instance, object name = null, bool withoutDisposalTracking = false) =>
72+
this.WireUp(instance.GetType(), instance, name, withoutDisposalTracking);
73+
7074
/// <inheritdoc />
7175
public IDependencyRegistrator WireUp(Type serviceType, object instance, object name = null, bool withoutDisposalTracking = false)
7276
{

0 commit comments

Comments
 (0)