Skip to content

Commit

Permalink
Changed the signature for Instance.RequiresServiceProvider to a metho…
Browse files Browse the repository at this point in the history
…d that takes in IMethodVariables
  • Loading branch information
Jeremy D. Miller authored and jeremydmiller committed Mar 5, 2023
1 parent d0ca874 commit a55f0dc
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 14 deletions.
5 changes: 3 additions & 2 deletions src/Lamar.Testing/IoC/Instances/ConstructorInstanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Lamar.IoC.Instances;
using Lamar.IoC.Resolvers;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
using Shouldly;
using StructureMap.Testing.Widget;
using Xunit;
Expand Down Expand Up @@ -179,7 +180,7 @@ public void requires_service_provider_with_dependencies_negative()

instance.CreatePlan(theGraph);

instance.RequiresServiceProvider.ShouldBeFalse();
instance.RequiresServiceProvider(Substitute.For<IMethodVariables>()).ShouldBeFalse();
}

[Fact]
Expand All @@ -196,7 +197,7 @@ public void requires_service_provider_with_dependencies_positive()

instance.CreatePlan(theGraph);

instance.RequiresServiceProvider.ShouldBeTrue();
instance.RequiresServiceProvider(Substitute.For<IMethodVariables>()).ShouldBeTrue();
}


Expand Down
2 changes: 1 addition & 1 deletion src/Lamar.Testing/IoC/Instances/LambdaInstanceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void derive_the_default_name()
public void requires_service_provider()
{
LambdaInstance.For(s => new Clock())
.RequiresServiceProvider.ShouldBeTrue();
.RequiresServiceProvider(null).ShouldBeTrue();
}


Expand Down
6 changes: 3 additions & 3 deletions src/Lamar/IoC/Frames/ServiceVariableSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public Variable Create(Type type)
return standin;
}

// TODO -- later, do we use other variables?
public void ReplaceVariables()
public void ReplaceVariables(IMethodVariables method)
{
if (_usesNestedContainerDirectly || _standins.Any(x => x.Instance.RequiresServiceProvider))
// TODO -- MORE HERE!!!!
if (_usesNestedContainerDirectly || _standins.Any(x => x.Instance.RequiresServiceProvider(method)))
{
useServiceProvider();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Lamar/IoC/Instances/Instance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public virtual object QuickResolve(Scope scope)

public int Hash { get; set; }

public virtual bool RequiresServiceProvider => Dependencies.Any(x => x.RequiresServiceProvider || x.ImplementationType == typeof(IContainer) || x.ImplementationType == typeof(IServiceProvider));
public virtual bool RequiresServiceProvider(IMethodVariables method) => Dependencies.Any(x => x.RequiresServiceProvider(method) || x.ImplementationType == typeof(IContainer) || x.ImplementationType == typeof(IServiceProvider));

public ServiceLifetime Lifetime { get; set; } = ServiceLifetime.Transient;

Expand Down
2 changes: 1 addition & 1 deletion src/Lamar/IoC/Instances/LambdaInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public LambdaInstance(Type serviceType, Func<TContainer, TReturn> factory, Servi

// This is important. If the lambda instance is a singleton, it's injected as a singleton
// to an object constructor and does not need the ServiceProvider
public override bool RequiresServiceProvider => Lifetime != ServiceLifetime.Singleton;
public override bool RequiresServiceProvider(IMethodVariables method) => Lifetime != ServiceLifetime.Singleton;
public string Description { get; set; }

public override Variable CreateVariable(BuildMode mode, ResolverVariables variables, bool isRoot)
Expand Down
2 changes: 1 addition & 1 deletion src/Lamar/IoC/Instances/ReferencedInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public override object QuickResolve(Scope scope)
return _inner.QuickResolve(scope);
}

public override bool RequiresServiceProvider => _inner.RequiresServiceProvider;
public override bool RequiresServiceProvider(IMethodVariables method) => _inner.RequiresServiceProvider(method);

public override Variable CreateInlineVariable(ResolverVariables variables)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Lamar/IoC/Lazy/FuncByNameInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override Variable CreateVariable(BuildMode mode, ResolverVariables variab
}


public override bool RequiresServiceProvider { get; } = true;
public override bool RequiresServiceProvider(IMethodVariables method) => true;

public override Func<Scope, object> ToResolver(Scope topScope)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Lamar/IoC/Lazy/FuncInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override Variable CreateVariable(BuildMode mode, ResolverVariables variab
}


public override bool RequiresServiceProvider { get; } = true;
public override bool RequiresServiceProvider(IMethodVariables method) => true;

public override Func<Scope, object> ToResolver(Scope topScope)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Lamar/IoC/Lazy/LazyInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public override Variable CreateVariable(BuildMode mode, ResolverVariables variab
}


public override bool RequiresServiceProvider { get; } = true;
public override bool RequiresServiceProvider(IMethodVariables method) => true;

public override object Resolve(Scope scope)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Lamar/Lamar.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<ItemGroup>
<PackageReference Include="JasperFx.TypeDiscovery" Version="1.0.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="[6.0.0, 8.0.0)" />
<PackageReference Include="JasperFx.CodeGeneration" Version="1.1.1" />
<PackageReference Include="JasperFx.Core" Version="1.1.0" />
<PackageReference Include="JasperFx.CodeGeneration" Version="2.0.0" />
<PackageReference Include="JasperFx.Core" Version="1.2.0" />
</ItemGroup>


Expand Down

0 comments on commit a55f0dc

Please sign in to comment.