Web API Solution demonstrates mutliteantcy architecture, using Entity Framework, UnitOfWork,Repository patterns
Todo list, accomplished tasks, can be found Here.
- Clone repository
- Apply Entity Framework migration. Run:
Update-DataBase
.
- (For Multitenancy testing) Change
DefaultConnection
to;Database=DeviceDb-ten2;
inappsettings.json
. Run EF migrationUpdate-DataBase
. It will create another database. - Tenants Database configuration stored in DataBaseManager (
tenantConfigurationDictionary
).
- Fill up valid database connection string configuration option in
appsettings.json
. - Run UnitTests.
- (Optional) Run API integration tests
- Build / Run.
DatabaseType
field is used to specify the database type the application should connect.
Currently, the framework contains connection information for:
- MsSql (MS SQLServer, Sql Express)
- Postgres NoSql (Information how to setup Postgres can be found here)
The value of DatabaseType
should come from DatabaseType
enum (src\DeviceManager.Api\Configuration\Settings) and should match the class name inside (src\DeviceManager.Api\Configuration\DatabaseTypes) and implement IDatabaseType
interface.
To add a new database type, just add a class implementing IDatabaseType
and add the same name inside DatabaseType
and change connection string in the DefaultConnection
property and DatabaseType
to new database type.
Application supports localization support though resource files. Currently, shared resource file is used to support support for English
and German
languages.
According to (Microsoft docs), to use a UI culture pass it as a query parameter (ui-culture=de-DE
).
All the resource values for each UI culture should be added to a resource file under Resources folder. The file name should include culture code.
Text values from resource files based on the UI culture is obtained from using the instance of IStringLocalizer<SharedResource> sharedLocalizer
which is injected via constructor. Then use this object to get resource values using sharedLocalizer["ResourceKey"].Value
.
Check Ping
action in BaseController.
Note: If only one of culture
or ui-culture
is sent in the query parameter then dotnetcore
uses same value for the other one.
To seed database with initial data update SeedData
method in DataSeederclass.
There can be multiple data seeding classes. To create a new data seeding class:
- Create a new data seeding class in the same folder inheriting from IDataSeeder interface.
- Register new class in the IocContainerConfiguration class by replacing
DataSeeder
with new class name.
App image available in Docker Hub Registry: https://hub.docker.com/r/boriszn/devicemanagerapi/
You can pull image: docker pull boriszn/devicemanagerapi
The solution was migrated to the docker container and support docker compose orchestration. You can run docker using following options:
- Visual Studio 2017 Debug mode. Run VS (
F5
) will run docker container. - Docker CLI. Run in PS
docker run -p 8080:80 --rm -d boriszn/devicemanagerapi:latest
will run docker container in background (ordocker run -p 8080:80 boriszn/devicemanagerapi:latest
)
You can access the the Web API locally via URL: http://localhost:8080
To run/build project without docker, switch from Docker
to DeviceManagerApi
(specified in launchSettings.json
)
- In case of running from Docker Connection string should be changed to use IP addresses or real server domain names for
Server
parameter. AlsoUser Id
andPassword
should be added. For example:Server=192.168.1.36,1433;Database=DeviceDb;User Id=MyUser;Password=MySuperStringPassword;Trusted_Connection=True;MultipleActiveResultSets=true
Please be aware connection string like: Server=(localdb)\\mssqllocaldb;Database=DeviceDb;Trusted_Connection=True;MultipleActiveResultSets=true
will NOT work if app running from Docker container
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
All changes can be easily found in RELEASENOTES
This project is licensed under the MIT License