Repository navigation
Can I create instance of plain c# class via VContainer without registering it? #661
Replies: 1 comment
|
Resolve() itself expects T to already be registered in the container, so there isn't a built-in Resolve() mode that automatically treats every unknown concrete type as transient. However, if what you want is simply:
you can build a transient registration on the fly and resolve that registration directly: Then: For objects that are created frequently or are an actual part of your dependency graph, I would still prefer registering a factory: But for a truly one-off transient object, resolving an ad-hoc transient Registration is a compact option. One thing to keep in mind: because this object is outside your normal registered lifetime graph, I would consider the caller responsible for its lifetime/disposal if it owns unmanaged/disposable resources. |
Uh oh!
There was an error while loading. Please reload this page.
For monobehaviour i can use - container.InjectGameObject(gameObject). But if i need plain c# class instance: i register it first (builder.Register()), then resolve (await container and var instance = container.Resolve()).
Can i get similar result with only one operation? For situations when i definitely do not need that instance as dependency for any other class.
All reactions