Skip to content

Commit

Permalink
InstanceProducer<TService> added.
Browse files Browse the repository at this point in the history
InstanceProducer<TService> added that inherits from InstanceProducer and
adds a "TService GetInstance()" method. The generic
Lifestyle.CreateProducer methods return an InstanceProducer<TService>
(fixes #39).
  • Loading branch information
dot_net_junkie committed May 22, 2015
1 parent af18d70 commit 0ab9bb6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public void GetInstance_OnTwoPerThreadInstanceProducersForTheSameServiceType_Eac
var producer2 = threadLifestyle.CreateProducer<ICommand, ConcreteCommand>(container);

// Act
var instance1 = producer1.GetInstance();
var instance2 = producer2.GetInstance();
ICommand instance1 = producer1.GetInstance();
ICommand instance2 = producer2.GetInstance();

// Assert
Assert.AreNotSame(instance1, instance2, "Each instance producer should get its own cache.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void CreateRegistrationWithGeneric_RegisteringCovarientType_Succeeds()
container);

// Act
var instance = producer.GetInstance();
ICovariant<object> instance = producer.GetInstance();

// Assert
AssertThat.IsInstanceOfType(typeof(CovariantImplementation<string>), instance);
Expand Down
4 changes: 2 additions & 2 deletions SimpleInjector.NET.Tests.Unit/LifestyleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void GetInstance_OnProducerCreatedUsingLifestyleCreateProducer1_ReturnsEx
container.RegisterDecorator(typeof(IPlugin), typeof(PluginDecorator));

// Act
var instance = producer.GetInstance();
IPlugin instance = producer.GetInstance();

// Assert
AssertThat.IsInstanceOfType(typeof(PluginDecorator), instance);
Expand Down Expand Up @@ -144,7 +144,7 @@ public void GetInstance_OnProducerCreatedUsingLifestyleCreateProducer1_Expressio
};

// Act
var instance = producer.GetInstance();
IPlugin instance = producer.GetInstance();

// Assert
Assert.AreEqual(expectedRegisteredServiceType, actualRegisteredServiceType,
Expand Down
8 changes: 3 additions & 5 deletions SimpleInjector.NET/Lifestyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,11 @@ public static Lifestyle CreateCustom(string name, CreateLifestyleApplier lifesty
/// <returns>A new <see cref="InstanceProducer"/> instance.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="container"/> is a null
/// reference (Nothing in VB).</exception>
public InstanceProducer CreateProducer<TService, TImplementation>(Container container)
public InstanceProducer<TService> CreateProducer<TService, TImplementation>(Container container)
where TImplementation : class, TService
where TService : class
{
return new InstanceProducer(typeof(TService),
this.CreateRegistration<TService, TImplementation>(container));
return new InstanceProducer<TService>(this.CreateRegistration<TService, TImplementation>(container));
}

/// <summary>
Expand All @@ -407,8 +406,7 @@ public InstanceProducer CreateProducer<TService>(Func<TService> instanceCreator,
Container container)
where TService : class
{
return new InstanceProducer(typeof(TService),
this.CreateRegistration<TService>(instanceCreator, container));
return new InstanceProducer<TService>(this.CreateRegistration<TService>(instanceCreator, container));
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions SimpleInjector.PCL/SimpleInjector.PCL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@
<Compile Include="..\SimpleInjector.NET\InstanceProducer.cs">
<Link>InstanceProducer.cs</Link>
</Compile>
<Compile Include="..\SimpleInjector.NET\InstanceProducerOfT.cs">
<Link>InstanceProducerOfT.cs</Link>
</Compile>
<Compile Include="..\SimpleInjector.NET\Internals\ArgumentMapping.cs">
<Link>Internals\ArgumentMapping.cs</Link>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Version 3.0.0 (v3.0 RTM)
-[Core] Added Container.GetTypesToRegister method for batch registration. (fixes #7)
-[Core] Added Container.RegisterInstance overloads as replacement for RegisterSingle overloads that
take in an instance (fixes #44).
-[Core] InstanceProducer<TService> added that inherits from InstanceProducer and adds a
"TService GetInstance()" method. The generic Lifestyle.CreateProducer methods return an
InstanceProducer<TService> (fixes #39).

Breaking Changes:
-[Core] IConstructorVerificationBehavior merged with IConstructorVerificationBehavior (fixes #2).
Expand Down

0 comments on commit 0ab9bb6

Please sign in to comment.