Click here to Skip to main content
16,022,054 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I intend to build a small microservice using Java, C#, and Python with 3
main table "Accounts", "Orders", and "Products". I have done a few small API projects with C# before, but I forget most of them.

Anyway, the OrderService is the C# one that I want to ask.
I intend to organize it like this:
//
OrderServiceSolution
    OrderServiceProject
        ControllerFolder
            OrderServiceController
    OrderServiceLib
        ServiceFolder
        RepositoryFolder
        Entity(Object)Folder

//
Will this be ok? And since there is only one service, I don't need to use Generic Repository right?

What I have tried:

In addition, should I connect to the database using appsettings.json like this?
How do real projects connect to the database?

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
            IConfigurationRoot configuration = builder.Build();
            optionsBuilder.UseSqlServer(configuration.GetConnectionString("EStoreDB"));            
        }
Posted
Updated 7-Oct-24 21:29pm

1 solution

If the folders make sense to you, use them. Despite many opinionated people declaring that there is only "one true way" to do things like this, the reality is, as long as you are happy with it or, if you are doing this in an organisation that you align with project standards, then that's generally going to be good enough. Ultimately, naming is hard so if you get something that works for you, congratulations. Personally, I wouldn't have Folder in the name of a folder as that is redundant but that's me not you.

With regards to the configuration, I would try to avoid having sensitive configuration inside appsettings. There's too much risk of exposing secrets, such as database connection strings, if you accidentally commit them into something like github. In cases like this, I tend to use environment based configuration, and read this in from environment settings. That takes a bit of discipline, to make sure you remember to set that side up properly, but it reduces the likelihood of contaminating source control.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900