Skip to content

Commit dc275b4

Browse files
committed
Fix ApplicationManager to resolve #14 Sonal issues. Fix readme guide
1 parent 2ab9813 commit dc275b4

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Applications/ApplicationManager.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,30 @@ public abstract class ApplicationManager<TManager, TApplication>
1313

1414
public static bool IsStarted => AppContainer.IsValueCreated && AppContainer.Value.Driver.SessionId != null;
1515

16-
protected static TApplication GetApplication(Func<IServiceProvider, TApplication> startApplicationFunction, IServiceCollection serviceCollection = null)
16+
protected static TApplication GetApplication(Func<IServiceProvider, TApplication> startApplicationFunction, Func<IServiceCollection> serviceCollectionProvider = null)
1717
{
1818
if (!IsStarted)
1919
{
2020
AppContainer.Value = startApplicationFunction(
21-
GetServiceProvider(service => GetApplication(startApplicationFunction), serviceCollection));
21+
GetServiceProvider(service => GetApplication(startApplicationFunction, serviceCollectionProvider), serviceCollectionProvider));
2222
}
2323
return AppContainer.Value;
2424
}
2525

26-
protected static IServiceProvider GetServiceProvider(Func<IServiceProvider, TApplication> applicationSupplier, IServiceCollection serviceCollection = null)
26+
protected static IServiceProvider GetServiceProvider(Func<IServiceProvider, TApplication> applicationSupplier, Func<IServiceCollection> serviceCollectionProvider = null)
2727
{
2828
if (!ServiceProviderContainer.IsValueCreated)
2929
{
30-
var services = serviceCollection;
31-
if (services == null)
30+
IServiceCollection services;
31+
if (serviceCollectionProvider == null)
3232
{
3333
services = new ServiceCollection();
3434
new Startup().ConfigureServices(services, applicationSupplier);
3535
}
36+
else
37+
{
38+
services = serviceCollectionProvider();
39+
}
3640
ServiceProviderContainer.Value = services.BuildServiceProvider();
3741
}
3842
return ServiceProviderContainer.Value;

Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Applications/ApplicationManagerTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ public void Should_BePossibleTo_RegisterCustomServices_WithCustomSettingsFile()
3636

3737
private class ApplicationManager : ApplicationManager<ApplicationManager, IApplication>
3838
{
39-
public static IApplication Application => GetApplication(StartApplicationFunction, RegisterServices(StartApplicationFunction));
39+
public static IApplication Application => GetApplication(StartApplicationFunction, () => RegisterServices(services => Application));
4040

41-
public static IServiceProvider ServiceProvider => GetServiceProvider(services => Application, RegisterServices(StartApplicationFunction));
41+
public static IServiceProvider ServiceProvider => GetServiceProvider(services => Application, () => RegisterServices(services => Application));
4242

4343
private static IServiceCollection RegisterServices(Func<IServiceProvider, IApplication> applicationSupplier)
4444
{
4545
var services = new ServiceCollection();
4646
var startup = new Startup();
47-
var settingsFile = new JsonFile($"Resources.settings.{SpecialSettingsFile}.json", Assembly.GetCallingAssembly());
47+
var settingsFile = new JsonFile($"Resources.settings.{SpecialSettingsFile}.json", Assembly.GetExecutingAssembly());
4848
startup.ConfigureServices(services, applicationSupplier, settingsFile);
4949
services.AddSingleton<ITimeoutConfiguration>(new CustomTimeoutConfiguration(settingsFile));
5050
return services;

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ Or, if you need to register your own services / rewrite the implementation, you
4141

4242
public class ApplicationManager : ApplicationManager<ApplicationManager, YourApplication>
4343
{
44-
public static YourApplication Application => GetApplication(StartApplicationFunction, RegisterServices(StartApplicationFunction));
44+
public static YourApplication Application => GetApplication(StartApplicationFunction, , () => RegisterServices(services => Application));
4545

46-
public static IServiceProvider ServiceProvider => GetServiceProvider(services => Application, RegisterServices(StartApplicationFunction));
46+
public static IServiceProvider ServiceProvider => GetServiceProvider(services => Application, , () => RegisterServices(services => Application));
4747

4848
private static IServiceCollection RegisterServices(Func<IServiceProvider, YourApplication> applicationSupplier)
4949
{

0 commit comments

Comments
 (0)