Question: ```
import json 

with open("madagascar.geojson") as f:
    data = json.load(f)

```

I am completely lost as to where to go with this. This is all the code I have produced, as I am new to python. I have a Madagascar geojson file I am trying to read using json. Once I have done that I would like to print out the 5th region in the data set using a phrase to the effect of "“The fifth record is for X, whose area is Y sq km." with X being region name and Y being the area.

How would I go about doing this? 

GeoJSON text file: <https://drive.google.com/file/d/1we40zpuGQICfyTw7YtJ39OY7gtPUQJr7/view?usp=sharing>

Answer: 
> 
> But when i create an instance by using `new` keyword, dependency injection doesn't work.
> 
> 
> 

That’s fundamentally how dependency injection works.

With dependency injection, you are simply not supposed to `new` up new objects. That’s the whole point of [dependency injection](https://en.wikipedia.org/wiki/Dependency_injection) and [inversion of control](https://en.wikipedia.org/wiki/Inversion_of_control). Instead of creating objects and managing those objects’ dependencies, you are depending on the framework to *give* you the dependencies *you* need without having you to care about where they actually come from and how *they* are constructed properly. So you are moving the responsibility to create the object up to the caller.

If you find yourself in need to create an object that has a dependency, then this is a clear sign that you are doing it wrong. A common reason for this is that you want to create the object in order to manage its lifetime, or because it is actually a data object that just happens to have some operations that needs other dependencies to work (e.g. an entity that has a “save” method). In the first case, you simply don’t do it like that. You just depend on it and let the framework manage the lifetime; if it has an incorrect lifetime, then you should reconfigure it with the DI container.

In the latter case where you have a data object with operations, you should split this up. You should just have a data object, without any logic, and then inject some manager service that is able to perform the operation on that data object for you.

For example in ASP.NET Core Identity, you have the `User` object which is just a normal entity without any logic. In order to e.g. add user roles or change the password, you rely on the user manager which you can inject. So the `User` object itself is without any dependencies.

I’d generally suggest you to read the [dependency injection chapter](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-2.1) of the ASP.NET Core documentation to understand how dependency injection works and how it is supposed to be used within the framework.
As mentioned in the comments, it is not clear what you trying to achieve, but in order to do DI in .Net Core you have to create an interface IMyClass, then let your class implement that interface,

```
public interface IMyClass {
   void SampleMethod();
}

public class MyClass : IMyClass
{
    ILoginTokenKeyApi _loginTokenKeyApi;

    public MyClass(ILoginTokenKeyApi loginTokenKeyApi)
    {
        _loginTokenKeyApi = loginTokenKeyApi;
    }

    public void SampleMethod()
    {
        // method logic goes here...
        var xx = _loginTokenKeyApi.WhatEver;
    }
}

```

then register ILoginTokenProvider and IMyClass in startup.cs

```
services.AddTransient<ILoginTokenProvider, LoginTokenProvider>();
services.AddTransient<IMyClass, MyClass>();

```

finally inject IMyClass where you need it:

```
public class IndexModel : PageModel {

    private readonly IMyClass _myClass;

    public IndexModel(IMyClass myClass)
    {
        _myClass = myClass;
    }

    public void OnGet()
    {
       _myClass.SampleMethod();
    }
}

```

btw, it is also possible to register and inject MyClass without implementing IMyClass interface, but I prefer to follow basic programming principals :)