Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update HostFactoryResolver to account for lack of application name wi…
…th new host pattern

Based on dotnet/efcore#26198

The fix should go here, rather than in EF Core, because then anybody using this code will get the fixed behavior. I have tested this locally and it fixes https://github.com/dotnet/efcore/issues/26177. However tests should be added to this repo.
  • Loading branch information
ajcvickers authored Sep 29, 2021
commit 281736979cb0c59f4f17b1e415ee59d3d6d2ccd9
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -144,6 +145,14 @@ private static bool IsFactory<TReturn>(MethodInfo? factory)
{
return args =>
{
static bool IsApplicationNameArg(string arg)
=> arg.Equals("--applicationName", StringComparison.OrdinalIgnoreCase) ||
arg.Equals("/applicationName", StringComparison.OrdinalIgnoreCase);

args = args.Any(arg => IsApplicationNameArg(arg)) || assembly.FullName is null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is assembly.FullName null?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you're writing unit tests 😄

? args
: args.Concat(new[] { "--applicationName", assembly.FullName }).ToArray();

var host = hostFactory(args);
return GetServiceProvider(host);
};
Expand Down