|
41 | 41 | using Alex.Worlds.Multiplayer.Java;
|
42 | 42 | using Alex.Worlds.Singleplayer;
|
43 | 43 | using Microsoft.Extensions.DependencyInjection;
|
| 44 | +using Microsoft.Extensions.DependencyInjection.Extensions; |
44 | 45 | using Microsoft.Extensions.Hosting;
|
45 | 46 | using Microsoft.Xna.Framework;
|
46 | 47 | using Microsoft.Xna.Framework.Content;
|
|
54 | 55 | using RocketUI.Input.Listeners;
|
55 | 56 | using RocketUI.Utilities.Extensions;
|
56 | 57 | using RocketUI.Utilities.Helpers;
|
57 |
| -using SimpleInjector; |
58 | 58 | using SixLabors.ImageSharp;
|
59 | 59 | using SixLabors.ImageSharp.PixelFormats;
|
60 | 60 | using GpuResourceManager = Alex.Common.Graphics.GpuResources.GpuResourceManager;
|
@@ -285,59 +285,71 @@ protected override void Initialize()
|
285 | 285 |
|
286 | 286 | private void RegisterServiceContainer()
|
287 | 287 | {
|
288 |
| - SimpleInjector.Container container = new SimpleInjector.Container(); |
289 |
| - container.Options.ResolveUnregisteredConcreteTypes = true; |
| 288 | + var container = new ServiceCollection(); |
| 289 | + //container.Options.ResolveUnregisteredConcreteTypes = true; |
290 | 290 |
|
291 |
| - container.RegisterInstance<Game>(this); |
292 |
| - container.RegisterInstance<Alex>(this); |
293 |
| - container.RegisterInstance<IGraphicsDeviceService>(DeviceManager); |
294 |
| - container.RegisterInstance<GraphicsDevice>(GraphicsDevice); |
295 |
| - container.RegisterSingleton<IGuiRenderer, GuiRenderer>(); |
296 |
| - container.RegisterSingleton<GuiManager>(); |
297 |
| - container.RegisterSingleton<InputManager>(); |
298 |
| - container.RegisterInstance<IServiceProvider>(container); |
| 291 | + container.AddSingleton<Game>(this); |
| 292 | + container.AddSingleton<Alex>(this); |
| 293 | + container.AddSingleton<IGraphicsDeviceService>(DeviceManager); |
| 294 | + container.AddSingleton<GraphicsDevice>(GraphicsDevice); |
| 295 | + container.AddSingleton<IGuiRenderer, GuiRenderer>(); |
| 296 | + container.AddSingleton<GuiManager>(); |
| 297 | + container.AddSingleton<InputManager>(); |
| 298 | + //container.AddSingleton<IServiceProvider>(container); |
299 | 299 |
|
300 |
| - container.RegisterSingleton<JavaServerQueryProvider>(); |
301 |
| - container.RegisterSingleton<BedrockServerQueryProvider>(); |
| 300 | + container.AddSingleton<JavaServerQueryProvider>(); |
| 301 | + container.AddSingleton<BedrockServerQueryProvider>(); |
302 | 302 |
|
303 |
| - container.Register<IRegistryManager, RegistryManager>(Lifestyle.Singleton); |
| 303 | + container.AddSingleton<IRegistryManager, RegistryManager>(); |
304 | 304 |
|
305 |
| - container.RegisterSingleton<ResourceManager>(); |
306 |
| - container.RegisterInstance<ServerTypeManager>(ServerTypeManager); |
307 |
| - container.Register<XboxAuthService>(Lifestyle.Singleton); |
| 305 | + container.AddSingleton<ResourceManager>(); |
| 306 | + container.AddSingleton<ServerTypeManager>(ServerTypeManager); |
| 307 | + container.AddSingleton<XboxAuthService>(); |
308 | 308 |
|
309 |
| - container.Register<BlobCache>(Lifestyle.Singleton); |
310 |
| - container.Register<ResourcePackCache>(Lifestyle.Singleton); |
| 309 | + container.AddSingleton<BlobCache>(); |
| 310 | + container.AddSingleton<ResourcePackCache>(); |
311 | 311 |
|
312 |
| - container.RegisterInstance<ContentManager>(Content); |
313 |
| - container.RegisterInstance<IStorageSystem>(Storage); |
314 |
| - container.RegisterInstance<IOptionsProvider>(Options); |
315 |
| - container.RegisterInstance<Audio.AudioEngine>(AudioEngine); |
| 312 | + container.AddSingleton<ContentManager>(Content); |
| 313 | + container.AddSingleton<IStorageSystem>(Storage); |
| 314 | + container.AddSingleton<IOptionsProvider>(Options); |
| 315 | + container.AddSingleton<Audio.AudioEngine>(AudioEngine); |
316 | 316 |
|
317 |
| - container.RegisterSingleton<GuiPanoramaSkyBox>(); |
| 317 | + container.AddSingleton<GuiPanoramaSkyBox>(); |
318 | 318 |
|
319 | 319 | // RocketUI
|
320 |
| - container.Collection.Register<IInputListenerFactory>( |
| 320 | + container.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IInputListenerFactory), typeof(AlexKeyboardInputListenerFactory))); |
| 321 | + container.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IInputListenerFactory), typeof(AlexMouseInputListenerFactory))); |
| 322 | + container.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IInputListenerFactory), typeof(AlexGamePadInputListenerFactory))); |
| 323 | + |
| 324 | + /* |
321 | 325 | new Type[]
|
322 | 326 | {
|
323 | 327 | typeof(AlexKeyboardInputListenerFactory), typeof(AlexMouseInputListenerFactory),
|
324 | 328 | typeof(AlexGamePadInputListenerFactory)
|
325 |
| - }, Lifestyle.Singleton); |
| 329 | + }, Lifestyle.Singleton);*/ |
326 | 330 |
|
327 |
| - container.Collection.Register<IHostedService>(typeof(Alex).Assembly); |
| 331 | + foreach (var s in typeof(Alex).Assembly.GetTypes()) |
| 332 | + { |
| 333 | + if (typeof(IHostedService).IsAssignableFrom(s)) |
| 334 | + { |
| 335 | + container.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IHostedService), s)); |
| 336 | + } |
| 337 | + } |
328 | 338 |
|
329 | 339 | if (LaunchSettings.RocketDebugging)
|
330 | 340 | {
|
331 |
| - container.RegisterSingleton<RocketDebugSocketServer>(); |
332 |
| - container.Collection.Append<IHostedService, RocketDebugSocketServer>(); |
| 341 | + //container.AddSingleton<RocketDebugSocketServer>(); |
| 342 | + container.AddHostedService<RocketDebugSocketServer>(); |
| 343 | + //container.Collection.Append<IHostedService, RocketDebugSocketServer>(); |
333 | 344 | }
|
334 | 345 |
|
335 | 346 | PluginManager.Initiate(container, Options, LaunchSettings);
|
336 | 347 |
|
337 |
| - container.Verify(); |
338 |
| - Services.AddService<IServiceProvider>(container); |
| 348 | + var c = container.BuildServiceProvider(); |
| 349 | + //container.Verify(); |
| 350 | + Services.AddService<IServiceProvider>(c); |
339 | 351 |
|
340 |
| - ServiceContainer = container; |
| 352 | + ServiceContainer = c; |
341 | 353 | PluginManager.Setup(ServiceContainer);
|
342 | 354 | }
|
343 | 355 |
|
|
0 commit comments