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
DNN now has a lot of DI, but it's still missing the classic Lazy<Service>.
This is important to request a service which may not be used, so we don't want to initialize it when not used.
This was already discussed at DNN connect, and I think it's for @bdukes
Description of solution
This is a very classic setup:
Create the 3-lines Lazy-implementation
Register it
Usable
using System;namespace DotNetNuke.WhateverShouldBeTheNamespace
{/// <summary>/// Enables lazy requesting of objects - won't be available until needed./// This is a classic plain-vanilla implementation of Lazy for ServiceProviders./// </summary>publicclassLazyImplementation<TService>:Lazy<TService>{publicLazyImplementation(IServiceProvidersp):base(sp.Build<TService>){}}}
Register it like this:
publicstatic IServiceCollection AddLibDI(thisIServiceCollectionservices){// Lazy objects in General
services.TryAddTransient(typeof(Lazy<>),typeof(LazyImplementation<>));
...
Description of problem
DNN now has a lot of DI, but it's still missing the classic
Lazy<Service>
.This is important to request a service which may not be used, so we don't want to initialize it when not used.
This was already discussed at DNN connect, and I think it's for @bdukes
Description of solution
This is a very classic setup:
Register it like this:
Use like this:
Description of alternatives considered
This is super-standard, so there are not many alternatives (except for not using Lazy, or using a different DI system).
The text was updated successfully, but these errors were encountered: