Replies: 4 comments 4 replies
-
Can you show the entire AppHost project's Program.cs and the application's Program.cs (where the DbContext wire up is happening?) |
Beta Was this translation helpful? Give feedback.
-
Hi @davidfowl, the AppHost is https://github.com/Project-KONGOR-Open-Source/ASPIRE/blob/main/ASPIRE.AppHost/ASPIRE.cs and the database project is https://github.com/Project-KONGOR-Open-Source/ASPIRE/blob/main/MERRICK.Database/MERRICK.cs. Essentially, what I'm trying to achieve is to give https://github.com/Project-KONGOR-Open-Source/ASPIRE/blob/main/ZORGATH.WebPortal.API/ZORGATH.cs access to the database context without duplicating the connection string in the configuration, if that is possible. |
Beta Was this translation helpful? Give feedback.
-
Also, thank you very much for the prompt response! |
Beta Was this translation helpful? Give feedback.
-
I don't know how to do it with Aspiere, but you can add a key vault and store the connection string there. The key vault can be added to the Aspiere host and injected into the other applications. |
Beta Was this translation helpful? Give feedback.
-
I've been following the eShopLite example but I can't figure out what is going on because when I try to inject my database context I keep getting
"ConnectionString is missing. It should be provided in 'ConnectionStrings:database' or under the 'ConnectionString' key in 'Aspire:Microsoft:EntityFrameworkCore:SqlServer' or 'Aspire:Microsoft:EntityFrameworkCore:SqlServer:DatabaseContext' configuration section."
. This is (roughly) my setup.I've got a database manager project that registers a SQL Server service...
builder.AddSqlServerDbContext<MyContext>("MyConnectionStringName");
...and everything works fine in that project.
The Aspire.AppHost builder looks like something along the lines of...
But if I register
MyContext
as a dependency in my API project and try to inject it into a controller it doesn't quite work, and I'm not sure what I'm doing wrong. I was expecting that if I just dobuilder.AddSqlServerDbContext<MyContext>("MyConnectionStringName");
in my API project then there is some magic that happens behind the scenes and the connection string is retrieved from some shared Aspire context.In the eShopLite sample solution I noticed that one project had some JSON config along the lines of...
...so I tried a placeholder connection string in my API project too, but that didn't work either.
Could someone please point me in the right direction, because I'm not sure what I'm doing wrong. I just want to reference my database context from my API project without duplicating the connection string. Is this possible?
Beta Was this translation helpful? Give feedback.
All reactions