Inject Attribute

I have a situation where I want to perform the same actions in two different pages, to avoid code duplication, I created a Utilities class with a method that does what I want the two pages to do.

My question is why does injecting the services not work?

I have to pass the services into the method to get things to work...

I don't understand constructor injection.

If you have a constructor that requires you pass in the service you are wanting to be available, what is the point?

I need my regular class named Utilities to have the sql_databaseService available for use without having to pass it in (constructor injection).

I have a separate project Console app that calls my Utilities class in my Radzen Blazor Server app. I don't have the sql_databaseService available in the Console app, so I can't pass it to the Utilities class.

Any suggestions?

Hey @Chad,

I’m afraid that we can’t change how Blazor dependency injection works. Maybe it will be better to ask such questions on StackOverflow.

I understand, just frustrated, so thought I'd ask.

I just posted on StackOverflow.

I'm not asking to change how it works, just trying to understand it better.

Any suggestions for my scenario?

I think I have to figure out how to make the service available in the console app so I can pass it along with the data to my Utilities class.

I'll need this when I start working on my mobile app too.

Maybe build an API that uses sql_databaseService and just call that API from my console app and my mobile app when I get that far?

This is exactly how WebAssembly works - maybe it will be better option for your case.

1 Like

It's the same difference though.

I built a Blazor WebAssembly Application from Radzen Blazor Studio

The client pages inject the sql_databaseService just like the pages in my Blazor Server Application

I'm going to need a way to interact with the database outside of the main application.

Is there any database service and/or API support?