Skip to content

Commit 41cf318

Browse files
committed
added some docs
1 parent 5dc1728 commit 41cf318

File tree

7 files changed

+110
-4
lines changed

7 files changed

+110
-4
lines changed

.prettierignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ assets/js/search-data.json
88
assets/js/zzzz-search-data.json
99
assets/js/just-the-docs.js
1010
*.md
11-
_includes/mermaid_config.js
11+
<!-- _includes/mermaid_config.js -->

_config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ search:
8787
enable_copy_code_button: true
8888

8989
# By default, consuming the theme as a gem leaves mermaid disabled; it is opt-in
90-
mermaid:
90+
#mermaid:
9191
# Version of mermaid library
9292
# Pick an available version from https://cdn.jsdelivr.net/npm/mermaid/
93-
version: "10.9.0"
93+
#version: "10.9.0"
9494
# Put any additional configuration, such as setting the theme, in _includes/mermaid_config.js
9595
# See also docs/ui-components/code
9696
# To load mermaid from a local library, also use the `path` key to specify the location of the library; e.g.

_includes/head_custom.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
position: absolute;
1515
}
1616

17+
pre.highlight {
18+
padding-bottom: 12px !important;
19+
}
20+
1721
.highlight .p {
1822
color: #dee2f7 !important;
1923
}

docs/testing/moq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: MOQ
2+
title: MoQ
33
parent: Testing
44
layout: default
55
published: true

quick.md renamed to gists.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ permalink: /gists
1414
git cherry-pick <commit sha>
1515
```
1616

17+
``` powershell
18+
git rebase origin/master
19+
```
20+
1721
### RoboCopy
1822
---
1923
```powershell

missing-things.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
layout: default
3+
title: Unofficial
4+
nav_order: 2
5+
description: "Things that are not provided by default by the owner."
6+
permalink: /unofficial
7+
---
8+
9+
# This page contains the concepts or code that most major libraries doesn't provide by default.
10+
11+
12+
## .NET 6+
13+
14+
### Alias for DI.
15+
16+
- .NET 6 doesn't have the proper alaising concept in the DI. So we can implement a Factory Pattern and solve this.
17+
18+
```csharp
19+
20+
public interface IDBContext
21+
{
22+
string Source {get;}
23+
24+
Database Database {get;}
25+
}
26+
27+
28+
public interface IDBContextFactory
29+
{
30+
IDBContext GetDBContext(string source); // you can use a enum too here.
31+
}
32+
33+
public class DBContextFactory : IDBContextFactory
34+
{
35+
private readonly IEnumerable<IDBContext> _dbContexts;
36+
public DBContextFactory(IEnumerable<IDBContext> dbContexts)
37+
{
38+
_dbContexts = dbContexts;
39+
}
40+
41+
public IDBContext GetDBContext(string source)
42+
{
43+
return _dbContexts.Where(_=>_.Source == source).FirstOrDefault();
44+
}
45+
}
46+
47+
// registations in DI.
48+
49+
services.AddScoped<IDBContextFactory, DBContextFactory>();
50+
services.AddScoped<IDBContext, CartDBContext>(); // pass source as Cart and hard code that in the implementation
51+
services.AddScoped<IDBContext, OrderDBContext>(); // pass source as Order and hard code that in the implementation
52+
services.AddScoped<IDBContext, LogDBContext>(); // pass source as Log and hard code that in the implementation
53+
services.AddScoped<IDBContext, ProductsDBContext>(); // pass source as Products and hard code that in the implementation
54+
55+
// You can use Enum as well and avoid strings.
56+
```

my_best_practices.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
layout: default
3+
title: My Best Practices
4+
nav_order: 2
5+
description: "My Best Practices"
6+
permalink: /best-pactices
7+
---
8+
9+
## MVC / Web API
10+
11+
- If you have to read anything from HttpContext then always ensure you use an interface like below. This removes the burden of mocking HttpContext in unit tests.
12+
13+
```csharp
14+
public interface ICustomHttpContextAccessor
15+
{
16+
int GetProjectId();
17+
}
18+
19+
public class CustomHttpContextAccessor
20+
{
21+
public int GetProjectId()
22+
{
23+
// your logic to read the project id from route data or from query params or from claims etc.
24+
}
25+
}
26+
```
27+
28+
In Unit Tests, you can easily mock `ICustomHttpContextAccessor`. .NET Core provides `IHttpContextAccessor`, but this provides the access to the HttpContext only. So it's good to have our own interface that can be common accross the project. You can inject the `IHttpContextAccessor` into `ICustomHttpContextAccessor`.
29+
30+
## Design Patterns
31+
32+
- Avoid using Service Locator Pattern as it causes lot of trouble when writing unit tests.
33+
- It's totally OK to have more thna 5 parameters inside a constructor but when you pass `IServiceProvider` and resolve the required things inside constructor it's going to be painfull at some point in time.
34+
35+
## Database
36+
- Check the cost of queries when working with stored procedures or views and optimize them before moving to production.
37+
- Ensure proper indexes on table's with large data. Once I encountered a sitaution where fetching one record based on 4 conditions used to take 6 minutes. Once I created the index on the columns for all these 4 conditions it took less than 2 seconds. That's the beauty of indexes.
38+
39+
## ORM (EF & EF Core)
40+
- Ensure to dispose the `DBContext` properly in Unit of Work.
41+
- Always use Unit of Work pattern when you have to operate on multiple tables like a transaction.
42+
- UoW must be scoped lifetime in DI and each instance must open it's own connection to the DB and close it in dispose.

0 commit comments

Comments
 (0)