IConfiguration is always NULL .NET CORE in Blazor app / Razor

sinfella

IConfiguration is always null no matter what i try.. I have also tried to add singleton to the startup class, but always null...

Startup class

        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

Here is my Security class

        IConfiguration _configuration { get;} **<<always null**
        public Security(IConfiguration configuration) **<<always null**
        {
            _configuration = configuration;
        }
         public  string GetConnectionString()
        {
            string connectionString = _configuration.GetConnectionString("localDb");
            return connectionString;

        }

Here is my Index.Razor page

 namespace WebbiSkoolsQuizManager.Pages
{
    public class IndexBase : ComponentBase
    {
        public IConfiguration Configuration { get; }
        public async Task TryLogin(string user, string pass)
        {
            
        }
       
         

        public async Task AddUserHash(string username, string password)
        {
            Security secure = new Security(Configuration);
            string connectionstring = secure.GetConnectionString();
            
            
        }
    }
}

Appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "ConnectionKeys": {
    "localDb": "Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=Quiz;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"

  },
  "AllowedHosts": "*"
}

Thank you in advance, i have searched high and low, regarding a fix for blazor specific but i cant find anything.. (P.S its .Net core 3)

enet

I guess this: public IConfiguration Configuration { get; }

Should be:

[Inject]
public IConfiguration Configuration { get; }

Note: You can't simply define a property of a service, and expect it to be populated... If you're using a Razor component class definition (.cs) as in your case, you can inject the service by using the [Inject] attribute. If you're using a Razor component (.razor), you can either use the @inject directive at the view portion of the component, as for instance:

@page "/"
@inject IConfiguration Configuration

or in the @code section, like this:

@code
{
    [Inject]
    public IConfiguration Configuration { get; }

}

Note also that if you want to inject a service into a normal C# class, you'll need to use constructor injection

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Asp.net core blazor vs .net core mvc with razor

From Dev

Asp.net core blazor vs .net core mvc with razor

From Dev

Error finding connection string in Blazor .net core app

From Dev

Asp.net core MVC post parameter always null

From Java

ASP.NET Core Get Json Array using IConfiguration

From Dev

ASP.NET Core Razor Pages - Complex model property is null after returning Page()

From Dev

ASP.NET Core: POSTing complex type from jQuery always results in 'null' model

From Dev

ASP.NET Core: POSTing complex type from jQuery always results in 'null' model

From Dev

Recursion in ASP.NET Core Razor views

From Java

Using Razor outside of MVC in .NET Core

From Dev

Razor in asp.net core is very slow

From Dev

Model is always null when submitting form from Razor view

From Dev

How to navigate to a blazor component from a razor page in a Blazor server-side app?

From Dev

App Settings .Net Core

From Dev

Accessing environment variables from ASP.NET Core 1 RC1 IConfiguration

From Dev

Accessing environment variables from ASP.NET Core 1 RC1 IConfiguration

From Java

ASP.NET Core Razor pages vs Full MVC Core

From Dev

getResourceAsStream always returning null (Google App Engine)

From Dev

Ajax Post Parameter is Always Null in MVC app

From Dev

UserManager always null in ASPNET Identity 2 app

From Dev

Ajax Post Parameter is Always Null in MVC app

From Java

Blazor vs Razor

From Java

Razor components vs Blazor

From Dev

Task Status always WaitForActivation using .NET Core

From Dev

.net core: ICollection in model always empty

From Dev

Sqlite-net extensions relations always null

From Dev

Is there a VB.NET expression that *always* yields null?

From Dev

Asp.net POST parameter always null

From Dev

Elasticsearch .net Client Nest querycontainer always null

Related Related

  1. 1

    Asp.net core blazor vs .net core mvc with razor

  2. 2

    Asp.net core blazor vs .net core mvc with razor

  3. 3

    Error finding connection string in Blazor .net core app

  4. 4

    Asp.net core MVC post parameter always null

  5. 5

    ASP.NET Core Get Json Array using IConfiguration

  6. 6

    ASP.NET Core Razor Pages - Complex model property is null after returning Page()

  7. 7

    ASP.NET Core: POSTing complex type from jQuery always results in 'null' model

  8. 8

    ASP.NET Core: POSTing complex type from jQuery always results in 'null' model

  9. 9

    Recursion in ASP.NET Core Razor views

  10. 10

    Using Razor outside of MVC in .NET Core

  11. 11

    Razor in asp.net core is very slow

  12. 12

    Model is always null when submitting form from Razor view

  13. 13

    How to navigate to a blazor component from a razor page in a Blazor server-side app?

  14. 14

    App Settings .Net Core

  15. 15

    Accessing environment variables from ASP.NET Core 1 RC1 IConfiguration

  16. 16

    Accessing environment variables from ASP.NET Core 1 RC1 IConfiguration

  17. 17

    ASP.NET Core Razor pages vs Full MVC Core

  18. 18

    getResourceAsStream always returning null (Google App Engine)

  19. 19

    Ajax Post Parameter is Always Null in MVC app

  20. 20

    UserManager always null in ASPNET Identity 2 app

  21. 21

    Ajax Post Parameter is Always Null in MVC app

  22. 22

    Blazor vs Razor

  23. 23

    Razor components vs Blazor

  24. 24

    Task Status always WaitForActivation using .NET Core

  25. 25

    .net core: ICollection in model always empty

  26. 26

    Sqlite-net extensions relations always null

  27. 27

    Is there a VB.NET expression that *always* yields null?

  28. 28

    Asp.net POST parameter always null

  29. 29

    Elasticsearch .net Client Nest querycontainer always null

HotTag

Archive