In memory or sql–part 27
When I want to perform tests , the SqlServer in memory is enough good. But , when in production, should have a proper connection string.
So I figured a simple way to understand this: if no connection string in appsettings.json, then use InMemory Sql Server . If there is, it should be a read connection string.
First, I have tried with
– but this is the old XML way – does not work with appsettings.json
I did not want to have DI in the constructor to read the file – so I realized that I can do this:
configuration = new ConfigurationBuilder()
This is not so good – because the code for retrieving looks like this:
var ConnectionString = InMemoryDB.sing.GetConRead(“DBRead”);
if (string.IsNullOrWhiteSpace(ConnectionString ))
opt = InMemoryDB.sing.MemoryOptions();
opt = new DbContextOptionsBuilder<InfoValutarContext>();
However,adding save and retrieve code ( with interfaces) , adding tests , adding controllers and DI on the WebAPI takes 1 hour
The commit is https://github.com/ignatandrei/InfoValutar/commit/ddd6fdc38bd8eee46d7fea0c54603c3644046cf6 and has 11 files .
InfovalutarAnd one hour passes...
(This is the result of 1 hour per day auto-challenge as a full cycle developer for an exchange rates application)
( You can see the sources at https://github.com/ignatandrei/InfoValutar/ )