How can I implement something similar to spring profiles when using Simple Injector IOC container in C#

Viewed 222

After some time in Java with Spring, I'm trying to take all of IOC principles into some old and new C# Code, I've started using simple injector after reading some comparisons. I need different profiles in order to load different objects to my container. I have tried the following solution: configuring a variable in the app.config file with the name of Profile and then after reading it the code goes as follows:

        if (_profile.Equals("unit-test"))
        {
            _container.Register<ParkingService, ParkingService>(Lifestyle.Singleton);
            _container.Register<ITimeServices, TimeServicesMock>(Lifestyle.Singleton);
            _container.Register<IStorageServices, InMemoryStorage>(Lifestyle.Singleton);
        }

        else if (_profile.Equals("integration-test"))
        {
            _container.Register<ParkingService, ParkingService>(Lifestyle.Singleton);
            _container.Register<ITimeServices, TimeServices>(Lifestyle.Singleton);
            _container.Register<IStorageServices, MongoStorage>(Lifestyle.Singleton);
        }

Is there any out of the box solution for this or a better way of implementation?

0 Answers
Related