Dependency Injection in Oqtane
Oqtane has used Dependency Injection since day one, so it's much better integrated than with Dnn.
How Can I Get Oqtane Objects using Dependency Injection?
Oqtane uses the same Dependency Injection like 2sxc, so your Razor-Code can access all Oqtane objects using GetService<ISomeOqtaneInterface>()
.
Just be aware of the fact that Oqtanes architecture is very different from the classic setup, so many services documented in the Oqtane docs will actually behave as remote services, so they will internally call http-endpoints to perform their work. This makes many Oqtane Services a bit slower than you might expect.
Can I Use Razor .net Core @inject in Oqtane?
Yes you can, as the 2sxc DI is fully integrated with the Oqtane DI. So your Razor could also do this:
@inject ICmsContext Context
How can I get 2sxc Objects in Oqtane Blazor Controls?
This is currently not possible, as most of 2sxc runs on the server, while the Blazor controls run in the client.
We're working on this.
History of Dependency Injection in 2sxc
- 2sxc introduced Dependency Injection 1.1 in v9 (May 2017)
- Integrated with Oqtane DI in v12 (May 2021)
GetService<T>
pattern introduced for Razor/C# in v12 (May 2021)- Integrated with Oqtane DI in v12 (May. 2021)
- Upgraded to Dependency Injection 2.1 in v13 (Dec. 2021)
- Integrated with Dnn DI in v13 (Dec. 2021)
- Created ServiceKits for v14 (June 2022)
- Added ServiceKitLight for custom DataSources in 2sxc 15
- Added ServiceKit16 for 2sxc 16