Skip to content

Commit

Permalink
fiksing the first test for #507 using the FactoryDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Aug 1, 2022
1 parent a5cb081 commit 7fb806c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/DryIoc/Container.Generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ partial class Container
{
partial void GetLastGeneratedFactoryID(ref int lastFactoryID)
{
lastFactoryID = 205; // generated: equals to the last used Factory.FactoryID
lastFactoryID = 261; // generated: equals to the last used Factory.FactoryID
}

partial void ResolveGenerated(ref object service, Type serviceType)
Expand All @@ -62,7 +62,7 @@ partial void ResolveGenerated(ref object service,
requiredServiceType == null &&
Equals(preRequestParent, Request.Empty.Push(
typeof(IService),
200,
256,
typeof(MyService),
Reuse.Transient,
RequestFlags.IsResolutionCall)))
Expand Down Expand Up @@ -92,7 +92,7 @@ internal static object Get_IService_0(IResolverContext r) =>
null,
Request.Empty.Push(
typeof(IService),
200,
256,
typeof(MyService),
Reuse.Transient,
RequestFlags.IsResolutionCall|RequestFlags.StopRecursiveDependencyCheck),
Expand All @@ -104,7 +104,7 @@ internal static object Get_IService_0(IResolverContext r) =>
null,
Request.Empty.Push(
typeof(IService),
200,
256,
typeof(MyService),
Reuse.Transient,
RequestFlags.IsResolutionCall|RequestFlags.StopRecursiveDependencyCheck),
Expand Down
4 changes: 3 additions & 1 deletion src/DryIoc/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5204,7 +5204,9 @@ private static Expression GetFactoryDelegateExpressionOrDefault(Request request)
? request.RequiredServiceType.ThrowIfNull(Error.ResolutionNeedsRequiredServiceType, request)
: request.RequiredServiceType ?? wrapperType.GetGenericArguments()[0];

request = request.PushServiceType(serviceType);
request = request.PushServiceType(serviceType,
RequestFlags.IsWrappedInFunc | RequestFlags.IsDirectlyWrappedInFunc);

var container = request.Container;
var expr = container.ResolveFactory(request)?.GetExpressionOrDefault(request);
if (expr == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public class GHIssue507_Transient_resolve_with_opening_scope_using_factory_func_
public int Run()
{
Test_Simple();
Test_Original_issue();
return 1;
// Test_Original_issue();
return 2;
}

[Test, Ignore("fixme")]
[Test]
public void Test_Simple()
{
var c = new Container();
Expand All @@ -25,12 +25,16 @@ public void Test_Simple()

var gf = b.GetFoo;
Assert.IsNotNull(gf);

var f = gf(c.OpenScope());
Assert.IsNotNull(f);

}

class Bar2
{
public readonly Func<Foo2> GetFoo;
public Bar2(Func<Foo2> getFoo) => getFoo = GetFoo;
public readonly FactoryDelegate<Foo2> GetFoo;
public Bar2(FactoryDelegate<Foo2> getFoo) => GetFoo = getFoo;
}

class Foo2
Expand Down
1 change: 1 addition & 0 deletions test/DryIoc.TestRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void Run(Func<int> run, string name = null)
new Issue548_After_registering_a_factory_Func_is_returned_instead_of_the_result_of_Func(),
new GHIssue470_Regression_v5_when_resolving_Func_of_IEnumerable_of_IService_with_Parameter(),
new GHIssue506_WithConcreteTypeDynamicRegistrations_hides_failed_dependency_resolution(),
new GHIssue507_Transient_resolve_with_opening_scope_using_factory_func_in_singleton(),
new GHIssue471_Regression_v5_using_Rules_SelectKeyedOverDefaultFactory(),
};

Expand Down

0 comments on commit 7fb806c

Please sign in to comment.