ConnectionStrings passed from class to class
So, how does it work?
from here, the connectionstring is obtained without problems:
https://paste.mod.gg/nrvllbxtcqrq/0
but when this method is called from another method from here
https://paste.mod.gg/xccaugdrlvfw/0
it does not get the connectionstring, even just the processGameJson class when it's run it cannot get the connection string by itself, why?
BlazeBin - nrvllbxtcqrq
A tool for sharing your source code with the world!
BlazeBin - xccaugdrlvfw
A tool for sharing your source code with the world!
7 Replies
uhm first doesn't work
(also are you not using a DbContext?)
Not a direct answer to your question, but might I suggest just using dependency injection to inject an IDbConnection into the class? Much cleaner approach.
Program.cs
Also as a side note, for your query I recommend using actual parameters to protect against any sort of SQL injection, or other mishaps.
https://www.npgsql.org/doc/basic-usage.html#parameters
can u show how u register ur services to the container?
they dont use ef core, but a plain old ado.net driver
yeah sure!
not really sure what i'm doing tbh, just have to do this thing for an internship and it's just a mere prototype, so even if it doesn't have any security check it's fine
actually it's the first one that works ahah, when it's called from another program
if i'm running just the repos through swagger they all register fine
the moment i'm trying to call them through the ProcessGameJson all hell breaks loose
what .net core version are you using?
I assume you have a
Program.cs
file, where you are doing something like builder.Services.AddApplication()
based off of the extensions you provided.
So to expand upon my original point in that Program.cs
add the code I provided:
Then go back to your PlayersRepo
class and rework it to something like this:
also note: you are using an internal
class. be sure that where you inject/use this player repo is in the same assembly. If you wish to use it any other way, consider using a public
class for your player repo
One final callout: In your ProcessGameJson
class you are passing in a new player to the InsertPlayerAsync
method, but you only populated the ID property when you passed that object in, that will not work well with the way the InsertPlayerAsync
method is setup.
it does not get the connectionstringby that i assume that u get
null
, tbh i dont see anything that would cause that difference
actually, explain exactly how/what u observe, maybe its hidden somewhere therei meant the pastebin links
but apparently now i can open them