You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/bff/fundamentals/session/server-side-sessions.mdx
+36-7Lines changed: 36 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,9 +45,39 @@ builder.Services.AddBff()
45
45
options.UseSqlServer(cn);
46
46
});
47
47
```
48
+
The method of `AddEntityFrameworkServerSideSessions` registers the `SessionDbContext` along with a `UserSessionStore` as transient dependencies.
48
49
49
-
### Entity Framework Migrations
50
-
Most datastores that you might use with Entity Framework use a schema to define the structure of their data. *Duende.BFF.EntityFramework* doesn't make any assumptions about the underlying datastore, how (or indeed even if) it defines its schema, or how schema changes are managed by your organization. For these reasons, Duende does not directly support database creation, schema changes, or data migration by publishing database scripts. You are expected to manage your database in the way your organization sees fit. Using EF migrations is one possible approach to that, which Duende facilitates by publishing entity classes in each version of *Duende.BFF.EntityFramework*. An example project that uses those entities to create migrations is [here](https://github.com/DuendeSoftware/products/tree/main/bff/migrations/UserSessionDb).
50
+
For developers looking to take advantage of DbContext pooling or have more fine-grained control over their DbContext creation registration and creation process, you can use the `AddEntityFrameworkServerSideSessionsServices` method instead. This method registers all the required services for server-side session except for the `SessionDbContext`, which will now be managed by the DbContext pooling mechanism.
Note, you'll still need to let the server side session store know about the `SessionDbContext` by calling `AddEntityFrameworkServerSideSessions` with the `SessionDbContext` implementation as a generic argument.
67
+
68
+
### Entity Framework Migrations
69
+
70
+
Most data stores that you might use with Entity Framework use a schema to define the structure of their data. *Duende.BFF.EntityFramework* doesn't make any assumptions about the underlying datastore, how (or indeed even if) it defines its schema, or how schema changes are managed by your organization. For these reasons, Duende does not directly support database creation, schema changes, or data migration by publishing database scripts.
71
+
72
+
You are expected to manage your database in the way your organization sees fit. Using EF migrations is one possible approach to that, which Duende facilitates by publishing entity classes in each version of *Duende.BFF.EntityFramework*. An example project that uses those entities to create migrations is [here](https://github.com/DuendeSoftware/products/tree/main/bff/migrations/UserSessionDb).
73
+
74
+
To quickly create Entity Framework migrations, run the following command in the project directory that has access to Entity Framework Core's tools:
75
+
76
+
```bash
77
+
dotnet ef migrations add UserSessions -o Migrations
78
+
```
79
+
80
+
The project must also reference the `Duende.BFF.EntityFramework` NuGet package and the `Microsoft.EntityFrameworkCore.Design` NuGet package, along with a specific database provider and its corresponding configuration, including the connection string.
51
81
52
82
## Session Store Cleanup
53
83
Added in v1.2.0.
@@ -85,16 +115,16 @@ builder.Services.AddBff()
85
115
options.UseSqlServer(cn);
86
116
})
87
117
.AddSessionCleanupBackgroundProcess();`}/>
88
-
118
+
89
119
:::note
90
120
In V4, we changed how you enable session cleanup. We no longer automatically register the session cleanup hosted service. This has to be done manually.
91
121
In a load-balanced environment, you can choose to run the cleanup job on all instances the BFF. However, you can also decide to
92
-
spin up a separate host that's responsible for background jobs such as this cleanup job.
122
+
spin up a separate host that's responsible for background jobs such as this cleanup job.
93
123
:::
94
124
95
125
</TabItem>
96
126
<TabItemlabel="V3">
97
-
127
+
98
128
If you wish to have such sessions cleaned up periodically, then you can configure the *EnableSessionCleanup* and *SessionCleanupInterval* options:
0 commit comments