Skip to content

Commit

Permalink
@wip mangling with Request for #632
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Mar 6, 2024
1 parent 2f66cac commit b2a9c72
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Product>DryIoc.Microsoft.DependencyInjection</Product>

<VersionPrefix>8.0.0</VersionPrefix>
<VersionSuffix>preview-01</VersionSuffix>
<VersionSuffix>preview-02</VersionSuffix>

<AssemblyName>$(Product)</AssemblyName>
<AssemblyTitle>$(AssemblyName) $(TargetFramework)</AssemblyTitle>
Expand Down
33 changes: 26 additions & 7 deletions src/DryIoc/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ private object ResolveAndCacheKeyed(int serviceTypeHash, Type serviceType,
// Cache is missed, so get the factory and put it into cache:
ThrowIfRootContainerDisposed();

var request = Request.Create(this, serviceType, serviceKey, ifUnresolved, requiredServiceType, preResolveParent, default, args);
var request = Request.Create(this, ServiceInfo.Of(serviceType, requiredServiceType, ifUnresolved, serviceKey), preResolveParent, default, args);
var factory = ResolveFactory(request);
if (factory == null)
return null;
Expand Down Expand Up @@ -4827,7 +4827,7 @@ public static Expression GetRequestExpression(this IContainer container, Request
{
if (request.IsEmpty)
return (requestParentFlags & RequestFlags.OpensResolutionScope) != 0
? Field(typeof(Request).GetField(nameof(Request.EmptyOpensResolutionScope))) // we mat not refactor it to readonly field because it is rarely used
? Field(typeof(Request).GetField(nameof(Request.EmptyOpensResolutionScope))) // we may not refactor it to readonly field because it is rarely used
: Request.EmptyRequestExpr;

var flags = request.Flags | requestParentFlags;
Expand Down Expand Up @@ -10229,7 +10229,7 @@ internal static readonly RequestFlags InheritedFlags
new Request(null, null, 0, 0, null, default, null, null, null);

internal static readonly Expression EmptyRequestExpr =
Field(typeof(Request).GetField(nameof(Empty)));
Field(typeof(Request).GetField(nameof(Empty))); // todo: @perf UnsafeAccessAttribute, wrap this thing into a util method

/// <summary>Empty request which opens resolution scope.</summary>
public static readonly Request EmptyOpensResolutionScope =
Expand Down Expand Up @@ -10259,22 +10259,41 @@ public static Request Create(Container container, ServiceInfo serviceInfo,
{
var parentServiceType = preResolveParent.ActualServiceType;
var parentDetails = preResolveParent.GetServiceDetails();
if (parentDetails != null && parentDetails != ServiceDetails.Default)
if (parentDetails != null & parentDetails != ServiceDetails.Default)
serviceInfo = serviceInfo.InheritInfoFromDependencyOwner(parentServiceType, parentDetails, container, preResolveParent.FactoryType);

flags |= preResolveParent.Flags & InheritedFlags;
}
else
flags |= preResolveParent.Flags; //inherits the OpensResolutionScope flag

var inputArgExprs = inputArgs?.Map(a => Constant(a)); // todo: @check what happens if `a == null`, does the `object` type for is fine
var inputArgExprs = inputArgs?.Map(static a => Constant(a));

// we are re-starting the dependency depth count from `1`
return new Request(container, preResolveParent, 1, 0, null, flags, serviceInfo, serviceInfo.GetActualServiceType(), inputArgExprs);
}

/// <summary>Creates the Resolve request. The container initiated the Resolve is stored within request.</summary>
public static Request CreateResolutionRoot(Container container, Type serviceType, IfUnresolved ifUnresolved = IfUnresolved.Throw)
/// <summary>Creates the Resolve request for the resolution root service.</summary>
public static Request CreateResolutionRoot(Container container, ServiceInfo serviceInfo,
object[] inputArgs = null)
{
Debug.Assert(serviceInfo != null);

var serviceType = serviceInfo.ServiceType;
if (serviceType != null && serviceType.IsOpenGeneric())
Throw.It(Error.ResolvingOpenGenericServiceTypeIsNotPossible, serviceType);

var inputArgExprs = inputArgs?.Map(a => Constant(a));

var req = RentRequestOrNull();
return req == null
? new Request(container, Empty, 1, 0, null, RequestFlags.IsResolutionCall, serviceInfo, serviceInfo.GetActualServiceType(), inputArgExprs)
: req.SetServiceInfo(container, Empty, 1, 0, null, RequestFlags.IsResolutionCall, serviceInfo, serviceInfo.GetActualServiceType(), inputArgExprs);
}

/// <summary>Creates the Resolve request for the resolution root service.</summary>
public static Request CreateResolutionRoot(Container container, Type serviceType,
IfUnresolved ifUnresolved = IfUnresolved.Throw)
{
if (serviceType != null && serviceType.IsOpenGeneric())
Throw.It(Error.ResolvingOpenGenericServiceTypeIsNotPossible, serviceType);
Expand Down
2 changes: 1 addition & 1 deletion src/DryIoc/DryIoc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Product>DryIoc</Product>

<VersionPrefix>6.0.0</VersionPrefix>
<VersionSuffix>preview-06</VersionSuffix>
<VersionSuffix>preview-07</VersionSuffix>

<AssemblyName>$(Product)</AssemblyName>
<AssemblyTitle>$(AssemblyName) $(TargetFramework)</AssemblyTitle>
Expand Down
2 changes: 1 addition & 1 deletion test/DryIoc.TestRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Program
{
public static void Main()
{
new GHIssue631_Conditional_registrations().Run();
// new GHIssue631_Conditional_registrations().Run();

RunAllTests();

Expand Down

0 comments on commit b2a9c72

Please sign in to comment.