Skip to content

Commit e377ee3

Browse files
committed
SampleApp.WindowsServiceHosted launch/registrations refactoring
1 parent abdf05a commit e377ee3

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

src/SampleApps/SampleApp.WindowsServiceHosted/Program.cs

+9-10
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,21 @@ private static void Main(string[] args)
1717

1818
Args = args;
1919

20-
InitializeContainer();
20+
DIContainer.Current.RegisterAll().Verify();
2121

22-
if (new BasicServiceHandler<WebApplicationStartup>().Start(args))
23-
return;
22+
using var handler = new BasicServiceHandler<WebApplicationStartup>();
2423

25-
using (var scope = DIContainer.Current.BeginLifetimeScope())
26-
scope.Resolver.Resolve<WebApplicationStartup>().Run();
27-
28-
Console.ReadLine();
24+
if (!handler.Start(args))
25+
RunAsAConsoleApplication();
2926
}
3027

31-
private static void InitializeContainer()
28+
private static void RunAsAConsoleApplication()
3229
{
33-
IocRegistrations.Register();
30+
using var scope = DIContainer.Current.BeginLifetimeScope();
3431

35-
DIContainer.Current.Verify();
32+
scope.Resolver.Resolve<WebApplicationStartup>().Run();
33+
34+
Console.ReadLine();
3635
}
3736
}
3837
}

src/SampleApps/SampleApp.WindowsServiceHosted/SampleApp.WindowsServiceHosted.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFrameworks>net462</TargetFrameworks>
4+
<LangVersion>8.0</LangVersion>
45
<Authors>Alexander Krylkov</Authors>
56
<Product>Simplify</Product>
67
<Description>Simplify.Web as windows service sample app</Description>

src/SampleApps/SampleApp.WindowsServiceHosted/Setup/IocRegistrations.cs

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33

44
namespace SampleApp.WindowsServiceHosted.Setup
55
{
6-
public class IocRegistrations
6+
public static class IocRegistrations
77
{
8-
public static void Register()
8+
public static IDIContainerProvider RegisterAll(this IDIContainerProvider container)
99
{
10-
DIContainer.Current.Register<WebApplicationStartup>();
11-
1210
// Manual Simplify.Web bootstrapper registration
13-
DIContainer.Current.RegisterSimplifyWeb();
11+
container.RegisterSimplifyWeb()
12+
.Register<WebApplicationStartup>();
13+
14+
return container;
1415
}
1516
}
1617
}

0 commit comments

Comments
 (0)