Skip to content

Commit

Permalink
refactor: assemblies for DI
Browse files Browse the repository at this point in the history
  • Loading branch information
cherrynik committed Jun 20, 2024
1 parent d5c2716 commit 943348e
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -494,4 +494,5 @@ dependensee.html

# Jenny & CSharp
*.userproperties
Generated/
Generated/
src/Libs/External/MonoGame.ImGuiNet
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
using MonoGame.Aseprite.Sprites;
using Services.Math;


[assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.Components.ComponentsCompositionRoot))]

namespace GameDesktop.CompositionRoots.Components;

internal class ComponentsCompositionRoot : ICompositionRoot
Expand Down Expand Up @@ -115,7 +118,8 @@ private static void RegisterMovementAnimationsComponent(IServiceRegistry service

private static void RegisterTransformComponent(IServiceRegistry serviceRegistry)
{
serviceRegistry.RegisterSingleton(_ => new TransformComponent());
serviceRegistry.Register<string, NameComponent>((factory, name) => new NameComponent(name));
serviceRegistry.RegisterTransient(_ => new TransformComponent());

serviceRegistry.RegisterSingleton(_ =>
new TransformComponent { Position = new(316, 116) }, "PlayerEntity");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// using Features.Debugging;

using LightInject;
using MonoGame.ImGuiNet;

[assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.DebugFeatures.DebugRootFeatureCompositionRoot))]
namespace GameDesktop.CompositionRoots.DebugFeatures;

internal class DebugRootFeatureCompositionRoot : ICompositionRoot
Expand All @@ -16,10 +18,10 @@ private static void RegisterSystems(IServiceRegistry serviceRegistry)
{
// serviceRegistry.RegisterSingleton(factory =>
// {
// return new DrawRectangleCollisionComponentsSystem(factory.GetInstance<ILogger>());
// return new DrawRectangleCollisionComponentsSystem(factory.GetInstance<ILogger>());
// });
}

// private static void RegisterFeature(IServiceRegistry serviceRegistry) =>
// serviceRegistry.RegisterSingleton<DebugRootFeature>();
// serviceRegistry.RegisterSingleton<DebugRootFeature>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Entities.Factories.Characters;
using LightInject;

[assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.Entities.PlayerEntityCompositionRoot))]

namespace GameDesktop.CompositionRoots.Entities;

internal class PlayerEntityCompositionRoot : ICompositionRoot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Entities.Factories.Items;
using LightInject;

[assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.Entities.RockEntityCompositionRoot))]
namespace GameDesktop.CompositionRoots.Entities;

public class RockEntityCompositionRoot : ICompositionRoot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Entities.Factories.Characters;
using LightInject;

[assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.Entities.StaticEntityCompositionRoot))]

namespace GameDesktop.CompositionRoots.Entities;

internal class StaticEntityCompositionRoot : ICompositionRoot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
using GameDesktop.CompositionRoots.DebugFeatures;
#endif

[assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.Features.RootFeatureCompositionRoot))]

namespace GameDesktop.CompositionRoots.Features;

internal class RootFeatureCompositionRoot : ICompositionRoot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Services.Factories;
using Services.Math;

[assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.FundamentalCompositionRoot))]

namespace GameDesktop.CompositionRoots;

internal class FundamentalCompositionRoot : ICompositionRoot
Expand Down
2 changes: 2 additions & 0 deletions src/Apps/GameDesktop/CompositionRoots/GameCompositionRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using Microsoft.Xna.Framework;
using Serilog;

[assembly: CompositionRootType(typeof(GameDesktop.CompositionRoots.GameCompositionRoot))]

namespace GameDesktop.CompositionRoots;

internal class GameCompositionRoot : ICompositionRoot
Expand Down
7 changes: 3 additions & 4 deletions src/Libs/Entities/Factories/EntityFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public class AbstractEntityFactory(IServiceFactory serviceFactory) : IAbstractEn
private readonly Dictionary<string, IAbstractEntityFactory> _factories = new()
{
// { "Tree", () => (IEntityFactory)serviceProvider.GetService(typeof(RockFactory)) },
{ "Rock", serviceFactory.GetInstance<RockFactory>() },
{ "Default", null }
{ "Rock", serviceFactory.GetInstance<RockFactory>() }, { "Default", null }
};

public Entity CreateEntity(EntityInstance entity, World @in)
Expand All @@ -50,8 +49,8 @@ protected override void AddTags(Entity e)

protected override void AddData(Entity e)
{
// ref var name = ref e.AddComponent(serviceProvider.GetInstance<NameComponent>());
ref var transform = ref e.AddComponent(serviceProvider.GetInstance<TransformComponent>());
e.AddComponent(serviceProvider.GetInstance<string, NameComponent>("Pebble"));
e.AddComponent(serviceProvider.GetInstance<TransformComponent>());
}

protected override void AddRender(Entity e)
Expand Down

0 comments on commit 943348e

Please sign in to comment.