Elfocrash / Cosmonaut

🌐 A supercharged Azure CosmosDB .NET SDK with ORM support
https://cosmonaut.readthedocs.io
MIT License
342 stars 44 forks source link

InvalidOperationException #15

Closed kklan closed 6 years ago

kklan commented 6 years ago

So I was following what you suggested that I create another collection to save relationships.

This is how I set it up:

  1. Model

    screen shot 2018-05-20 at 2 40 16 pm
  2. Initiation:

    screen shot 2018-05-20 at 2 40 29 pm
  3. Post Method:

    screen shot 2018-05-20 at 2 40 44 pm

But I'm getting error:

screen shot 2018-05-20 at 2 44 44 pm

Do I need to create another controller to handle this?

Elfocrash commented 6 years ago

You can just have both your ICosmosStores in the same contractor. The .NET Core DI framework doesn't support multiple contractors.

You can also use the [FromServices] attribute to get the store in the specific method.

kklan commented 6 years ago

Is there anyway you can provide an example of syntax when you say both ICosmosStores in same contractor?

Elfocrash commented 6 years ago

Something like this

    private readonly ICosmosStore<Car> _carStore;
    private readonly ICosmosStore<FriendStore> _friendStore;

    public HomeController(ICosmosStore<Car> carStore, ICosmosStore<FriendStore> friendStore)
    {
        _carStore = carStore;
        _friendStore = friendStore;
    }
kklan commented 6 years ago

Great thank you.

kklan commented 6 years ago

Opps close it too soon.

I made the change and it's still not liking that. It's not creating the second collection.

screen shot 2018-05-20 at 3 19 25 pm
kklan commented 6 years ago

I just had to add in Startup.cs services.AddCosmosStore<Car>(settings); services.AddCosmosStore<Friend>(settings);