-
Notifications
You must be signed in to change notification settings - Fork 13
Runtimes
Runtime implements aspects. Single runtime may implement one or more aspects usually using some 3rd-party technology under the hood. Runtimes are being delivered by separate NuGet packages. Currently Tecture offers single runtime for ORM and DirectSql aspects based on EntityFramework Core. This runtime is called Reinforced.Tecture.Runtimes.EFCore and available as NuGet package.
Keep in mind that runtime may contain dependencies on 3rd-party packages whether aspects usually do not. So in order to use EF.Core runtime, you have to install it:
PM> Install-Package Reinforced.Tecture.Runtimes.EfCore
Binding channels to exact runtime is pretty similar to typical IoC registration, but usually is much shorter.
Runtimes are being connected to each channel according to aspects that they use. All the aspects used by channel must be fullfilled with runtimes when integrating Tecture into your system. This can be done when you create TectureBuilder
object as follows:
var ld = new LazyDisposable<MyDbContext>(() => new MyDbContext());
var tb = new TectureBuilder();
tb.WithChannel<Db>(c =>
{
// these extensions are being supplied by runtime
c.UseEfCoreOrm(ld);
c.UseEfCoreDirectSql(ld);
// of course, if Db does not implement necessary aspects,
// this code produces compile-time error
});
ITecture tecture = tb.Build();
Build
method of TectureBuilder
implicitly validates that channels are correctly connected to runtimes. Unfortunately, there is no technical way to check that all the channels that are used in services are correctly initialized, so be careful. Of course, Tecture will throw runtime exception when it encounters runtime-unbound channel usage.
Also you can use following syntax:
c.UseEfCoreDirectSqlCommand(ld);
c.UseEfCoreOrmCommand(ld);
Runtimes supply extension methods that can be used to bind either query or command from channel. Keep it in mind when your channel extends CommandChannel<>
and QueryChannel<>
but not CommandQueryChannel<,>
.
(c) 2020, Pavel B. Novikov