Controller custom constructor for DI

Hi all
i have added a service and injected it as a singleton.
but i don't get how i can consume it in a controller.custom.cs

to use DI you have to add the service as a parameter of the constructor
but the contractor already exists in the other partial generated controller

generated controller

my partial for customizations

and ye c# partial classes doesn't support multiple constructors for DI

what can i do for DI? am i missing something?

1 Like

Hi @Genex,

Try defining a constructor with all dependencies as parameters. DI should pick that up when instantiating the controller.

Hey @korchev
well i can't add parameters to the auto-generated constructor, all my changes will be lost when radzen UI rebuilds... so what do you mean?


Add it in the partial file where are the other customizations.

Okay so adding the autogenerated partial constractor's parameter to MY partial doesn't solve the problem..


Auto Generated partial class

My Partial Class

in runtime i still get the same error when i test the controller..

is this happening because the resolver can't figure out which constructor to use???
doing some research on this topic....

or could it also be that the ODataController is not included in the partial class and that the private TMRGovernance.Data.TmrRadzenContext context; is not included in the partial class constructor ???