Pure.DI in Unity3d #83
Unanswered
AndreyProkopyev-azur
asked this question in
Q&A
Replies: 1 comment
-
Yes, it's possible. Please see this example: using Pure.DI;
var composition = new Composition();
var script = new ClientScript();
script = composition.BuildUp(script);
DI.Setup(nameof(Composition))
.Bind().To<Service1>()
.Bind().To<Service2>()
.Bind().To<ClientScript>(ctx =>
{
ctx.Inject("from arg", out ClientScript script);
ctx.BuildUp(script);
return script;
})
.RootArg<ClientScript>("clientScript", "from arg")
.Root<ClientScript>("BuildUp");
class ClientScript
{
[Ordinal(1)] public IService1 service1;
[Ordinal(2)] public IService2 service2;
}
interface IService1
{
};
internal class Service1 : IService1
{
};
interface IService2
{
};
internal class Service2 : IService2
{
}; The public ClientScript BuildUp(ClientScript clientScript)
{
clientScript.service1 = new Service1();
clientScript.service2 = new Service2();
return clientScript;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Do you have examples of using Pure.DI in Unity3d?
Code generation works well, however Unity3d scripts do not have single entry point and it's MonoBehaviours don't have constructors, so there is only service locator approach or assigning fields via roots.
Is there a way to implement something like this
?
Beta Was this translation helpful? Give feedback.
All reactions