rbxts-flamework / core

Flamework is an extensible game framework. It requires typescript and offers many useful features.
MIT License
101 stars 8 forks source link

Ability to add arbitrary instances into DI resolver #36

Closed caneva20 closed 2 years ago

caneva20 commented 2 years ago

Hi!

It would be pretty handy to be able to register my own "instances" into the framework's DI container. I love working with DI, but I couldn't find a way to register a logger I usually use (roblox-aurora/rbx-log) to be used with flamework's DI system, it doesn't need to be anything fancy, something like this would do just fine:

Flamework.addDependency(MY_DEPENDENCY_INSTANCE)
Fireboltofdeath commented 2 years ago

Currently, Flamework has an in-beta modding system (modding-v2 branch on relevant repositories, modding release on relevant npm packages) which allows you to specify custom decorators on classes which can then be resolved as singletons. Is this the behavior you desire, or do you specifically need to link an ID to a specific object for dependency injection?

Also, is there a reason you don't want to use a Service/Controller here?

Fireboltofdeath commented 2 years ago

This will be a feature in the new modding API https://github.com/rbxts-flamework/core/commit/70bdc654b38461fe2564361a53735370a0946805 which also includes other ways to augment dependency resolution (even completely overwriting Flamework's)

caneva20 commented 2 years ago

Sorry for the way too late response.

I'll have a look at the modding API and check what can be done with it, based on your second reply it seems to be what I was looking for, I'll let you know, thanks!

As to why I didn't use a controller/service, the reason is, I did use it, but it is not as great/simple as just throwing it into the container and just have it whenever I request one. The option I have right now is to create a wrapper as a controller/service for every external dependency I might want to use, it isn't a horrible option, it just isn't as great