Skip to content

Commit 7988890

Browse files
committed
simplify cretation of ServiceInfo #632
1 parent 9398c9a commit 7988890

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

src/DryIoc/Container.cs

+17-18
Original file line numberDiff line numberDiff line change
@@ -9538,11 +9538,6 @@ public static ServiceDetails Of(IfUnresolved ifUnresolved) =>
95389538
ifUnresolved == IfUnresolved.ReturnDefault ? IfUnresolvedReturnDefault :
95399539
IfUnresolvedReturnDefaultIfNotRegistered;
95409540

9541-
/// <summary>Creates new details out of provided settings and not null `serviceKey`.</summary>
9542-
[MethodImpl((MethodImplOptions)256)]
9543-
public static ServiceDetails OfServiceKey(ServiceDetails d, object serviceKey) =>
9544-
new ServiceDetails(d.RequiredServiceType, d.IfUnresolved, serviceKey, d.MetadataKey, d.Metadata, d.DefaultValue, hasCustomValue: false);
9545-
95469541
/// <summary>Creates new details out of provided settings, or returns default if all settings have default value.</summary>
95479542
public static ServiceDetails Of(Type requiredServiceType = null,
95489543
object serviceKey = null, IfUnresolved ifUnresolved = IfUnresolved.Throw,
@@ -9574,7 +9569,14 @@ public static ServiceDetails OfValue(object value) =>
95749569
/// <summary>Sets the service key as a detials of the service resolution.</summary>
95759570
[MethodImpl((MethodImplOptions)256)]
95769571
public static ServiceDetails OfServiceKey(object serviceKey) =>
9577-
new ServiceDetails(null, IfUnresolved.Throw, serviceKey, null, null, null, false);
9572+
new ServiceDetails(null, IfUnresolved.Throw, serviceKey, null, null, null,
9573+
hasCustomValue: false);
9574+
9575+
/// <summary>Creates new details out of provided settings and not null `serviceKey`.</summary>
9576+
[MethodImpl((MethodImplOptions)256)]
9577+
public static ServiceDetails WithServiceKey(ServiceDetails d, object serviceKey) =>
9578+
new ServiceDetails(d.RequiredServiceType, d.IfUnresolved, serviceKey, d.MetadataKey, d.Metadata, d.DefaultValue,
9579+
hasCustomValue: false);
95789580

95799581
/// <summary>Service type to search in registry. Should be assignable to user requested service type.</summary>
95809582
public readonly Type RequiredServiceType;
@@ -9892,17 +9894,14 @@ internal static object OrServiceType(Type serviceType, Type requiredServiceType,
98929894
if (serviceType == requiredServiceType)
98939895
requiredServiceType = null;
98949896

9895-
if (serviceKey == null & requiredServiceType == null & metadataKey == null & metadata == null)
9896-
{
9897-
if (ifUnresolved == IfUnresolved.Throw)
9898-
return serviceType; // todo: @wip
9899-
return ifUnresolved == IfUnresolved.ReturnDefault
9900-
? new TypedIfUnresolvedReturnDefault(serviceType)
9901-
: new TypedIfUnresolvedReturnDefaultIfNotRegistered(serviceType);
9902-
}
9897+
if (requiredServiceType == null & serviceKey == null & metadataKey == null & metadata == null)
9898+
return ifUnresolved == IfUnresolved.Throw ? serviceType
9899+
: ifUnresolved == IfUnresolved.ReturnDefault
9900+
? new TypedIfUnresolvedReturnDefault(serviceType)
9901+
: new TypedIfUnresolvedReturnDefaultIfNotRegistered(serviceType);
99039902

9904-
return new WithDetails(serviceType,
9905-
ServiceDetails.Of(requiredServiceType, serviceKey, ifUnresolved, null, metadataKey, metadata));
9903+
var details = new ServiceDetails(requiredServiceType, ifUnresolved, serviceKey, metadataKey, metadata, null, hasCustomValue: false);
9904+
return new WithDetails(serviceType, details);
99069905
}
99079906

99089907
/// <summary>Typed service info</summary>
@@ -10666,9 +10665,9 @@ public Request WithFlags(RequestFlags newFlags) =>
1066610665
public void ChangeServiceKey(object serviceKey) =>
1066710666
ServiceTypeOrInfo
1066810667
= ServiceTypeOrInfo is ServiceInfo i
10669-
? i.Create(i.ServiceType, ServiceDetails.OfServiceKey(i.Details, serviceKey)) // todo: @unclear check for the custom value
10668+
? i.Create(i.ServiceType, ServiceDetails.WithServiceKey(i.Details, serviceKey)) // todo: @unclear check for the custom value
1067010669
: ServiceTypeOrInfo is ParameterInfo pi
10671-
? ParameterServiceInfo.Of(pi, ActualServiceType, ServiceDetails.OfServiceKey(ServiceDetails.Default, serviceKey))
10670+
? ParameterServiceInfo.Of(pi, ActualServiceType, ServiceDetails.WithServiceKey(ServiceDetails.Default, serviceKey))
1067210671
: ServiceInfo.Of(ActualServiceType, serviceKey);
1067310672

1067410673
/// <summary>Prepends input arguments to existing arguments in request. It is done because the

0 commit comments

Comments
 (0)