Skip to content

Commit 584d7c7

Browse files
authored
Merge pull request #3730 from 2sic/develop
v21.03
2 parents 1d87e8b + d6862c0 commit 584d7c7

122 files changed

Lines changed: 795 additions & 471 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using ToSic.Sxc.Dnn.Run;
2-
using ToSic.Sxc.Services;
32
using ToSic.Sxc.Services.Sys;
43
using ToSic.Sxc.Sys.ExecutionContext;
54
using ExecutionContext = ToSic.Sxc.Sys.ExecutionContext.ExecutionContext;
@@ -12,12 +11,8 @@ internal class DnnExecutionContext<TModel, TServiceKit>(ExecutionContext.Depende
1211
where TModel : class
1312
where TServiceKit : ServiceKit
1413
{
15-
16-
// TODO: WE CAN PROBABLY DROP THIS CLASS, IF WE ALWAYS USE GetService<IDnnContext>(reuse: true) INSTEAD OF DNN
17-
1814
/// <summary>
1915
/// Dnn context with module, page, portal etc.
2016
/// </summary>
21-
public IDnnContext Dnn => _dnn.Get(GetService<IDnnContext>);
22-
private readonly GetOnce<IDnnContext> _dnn = new();
17+
public IDnnContext Dnn => field ??= GetService<IDnnContext>(reuse: true);
2318
}

Src/Dnn/ToSic.Sxc.Dnn.Core/Dnn/Code/DnnExecutionContext.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using ToSic.Sxc.Services;
2-
using ToSic.Sxc.Services.Sys;
1+
using ToSic.Sxc.Services.Sys;
32
using ExecutionContext = ToSic.Sxc.Sys.ExecutionContext.ExecutionContext;
43

54
namespace ToSic.Sxc.Dnn.Code;

Src/Dnn/ToSic.Sxc.Dnn.Core/Dnn/DnnModuleAndBlockBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal class DnnModuleAndBlockBuilder(
1818
private ILog ParentLog => (Log as Log)?.Parent ?? Log;
1919

2020

21-
protected override IModule GetModuleImplementation(int pageId, int moduleId)
21+
public override IModule GetModule(int pageId, int moduleId)
2222
{
2323
var l = Log.Fn<IModule>($"{nameof(pageId)}: {pageId}, {nameof(moduleId)}: {moduleId}");
2424
var moduleInfo = new ModuleController().GetModule(moduleId, pageId, false);

Src/Dnn/ToSic.Sxc.Dnn.Core/Dnn/Search/SearchController.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace ToSic.Sxc.Dnn.Search;
3939
internal class SearchController(
4040
AppsCacheSwitch appsCache,
4141
Generator<CodeCompiler> codeCompiler,
42-
Generator<IExecutionContextFactory> codeRootFactory,
42+
Generator<IExecutionContextFactory> exCtxFactory,
4343
Generator<ISite> siteGenerator,
4444
LazySvc<IModuleAndBlockBuilder> moduleAndBlockBuilder,
4545
LazySvc<ILookUpEngineResolver> dnnLookUpEngineResolver,
@@ -49,7 +49,7 @@ internal class SearchController(
4949
: ServiceBase("DNN.Search",
5050
connect:
5151
[
52-
appsCache, codeCompiler, codeRootFactory, siteGenerator, engineFactory, dnnLookUpEngineResolver,
52+
appsCache, codeCompiler, exCtxFactory, siteGenerator, engineFactory, dnnLookUpEngineResolver,
5353
moduleAndBlockBuilder, logStore, polymorphism
5454
])
5555
{
@@ -311,15 +311,20 @@ private ICustomizeSearch CreateAndInitViewController(ISite site, IBlock block)
311311
l.A("got instance of compiled ViewController class");
312312

313313
// 2. Check if it implements ToSic.Sxc.Search.ICustomizeSearch - otherwise just return the empty search results as shown above
314-
if (!(instance is ICustomizeSearch customizeSearch))
314+
if (instance is not ICustomizeSearch customizeSearch)
315315
return l.ReturnNull("exit, class do not implements ICustomizeSearch");
316316

317317
// 3. Make sure it has the full context if it's based on DynamicCode (like Code12)
318318
if (instance is INeedsExecutionContext instanceWithContext)
319319
{
320320
l.A($"attach DynamicCode context to class instance");
321-
var parentDynamicCodeRoot = codeRootFactory.New()
322-
.New(null, block, Log, CompatibilityLevels.CompatibilityLevel10);
321+
var parentDynamicCodeRoot = exCtxFactory.New().New(new()
322+
{
323+
OwnerOrNull = null,
324+
BlockOrNull = block,
325+
ParentLog = Log,
326+
CompatibilityFallback = CompatibilityLevels.CompatibilityLevel10,
327+
});
323328
instanceWithContext.ConnectToRoot(parentDynamicCodeRoot);
324329
}
325330

Src/Dnn/ToSic.Sxc.Dnn.Razor/Custom/Hybrid/RazorTyped.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public ITypedStack AsStack(params object[] items)
200200

201201
/// <inheritdoc cref="ITypedApi.AsStack{T}" />
202202
public T AsStack<T>(params object[] items)
203-
where T : class, IModelOfData, new()
203+
where T : class, IModelFromData, new()
204204
=> CodeApi.Cdf.AsStack<T>(items);
205205

206206
#endregion
@@ -225,12 +225,12 @@ public T AsStack<T>(params object[] items)
225225

226226
/// <inheritdoc />
227227
public T As<T>(object source, NoParamOrder npo = default)
228-
where T : class, IModelOfData
228+
where T : class, IModelFromData
229229
=> CodeApi.Cdf.AsCustom<T>(source: source);
230230

231231
/// <inheritdoc />
232232
public IEnumerable<T> AsList<T>(object source, NoParamOrder npo = default, bool nullIfNull = default)
233-
where T : class, IModelOfData
233+
where T : class, IModelFromData
234234
=> CodeApi.Cdf.AsCustomList<T>(source: source, npo: npo, nullIfNull: nullIfNull);
235235

236236
#endregion

Src/Dnn/ToSic.Sxc.Dnn.Razor/Dnn/Razor/Sys/DnnRazorCompiler.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,13 @@ private void InitHelpers(RazorComponentBase webPage)
179179
// All children which are then generated here should re-use that CodeApiService
180180
if (_sharedCodeApiService == null)
181181
{
182-
_sharedCodeApiService = exCtxFactory
183-
.New(webPage, Block, Log, compatibilityFallback: CompatibilityLevels.CompatibilityLevel9Old);
182+
_sharedCodeApiService = exCtxFactory.New(new()
183+
{
184+
OwnerOrNull = webPage,
185+
BlockOrNull = Block,
186+
ParentLog = Log,
187+
CompatibilityFallback = CompatibilityLevels.CompatibilityLevel9Old,
188+
});
184189

185190
// Since we just created a new CodeApiService, we must add this razor engine to it's piggyback
186191
_sharedCodeApiService.GetPiggyBack(nameof(DnnRazorCompiler), () => this);

Src/Dnn/ToSic.Sxc.Dnn.WebApi/Custom/Hybrid/ApiTyped.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public ITypedStack AsStack(params object[] items)
209209

210210
/// <inheritdoc cref="ITypedApi.AsStack{T}" />
211211
public T AsStack<T>(params object[] items)
212-
where T : class, IModelOfData, new()
212+
where T : class, IModelFromData, new()
213213
=> CodeApi.Cdf.AsStack<T>(items);
214214

215215
#endregion
@@ -299,12 +299,12 @@ public dynamic File(NoParamOrder npo = default,
299299

300300
/// <inheritdoc />
301301
public T As<T>(object source, NoParamOrder npo = default)
302-
where T : class, IModelOfData
302+
where T : class, IModelFromData
303303
=> CodeApi.Cdf.AsCustom<T>(source: source, npo: npo);
304304

305305
/// <inheritdoc />
306306
public IEnumerable<T> AsList<T>(object source, NoParamOrder npo = default, bool nullIfNull = default)
307-
where T : class, IModelOfData
307+
where T : class, IModelFromData
308308
=> CodeApi.Cdf.AsCustomList<T>(source, npo, nullIfNull);
309309

310310
#endregion

Src/Dnn/ToSic.Sxc.Dnn.WebApi/Dnn/Backend/Cms/EditController.cs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,25 @@ public class EditController() : DnnSxcControllerBase(RealController.LogSuffix),
1919
/// <inheritdoc />
2020
[HttpPost]
2121
[AllowAnonymous] // will check security internally, so assume no requirements
22-
public EditLoadDto Load([FromBody] List<ItemIdentifier> items, int appId)
23-
{
24-
var l = Log.Fn<EditLoadDto>($"Items: {items.Count}, AppId: {appId}");
25-
return l.ReturnAsOk(Real.Load(items, appId));
26-
}
22+
public async Task<EditLoadDto> Load([FromBody] List<ItemIdentifier> items, int appId) =>
23+
await Real.Load(items, appId);
2724

2825

2926
/// <inheritdoc />
3027
[HttpPost]
3128
[AllowAnonymous] // will check security internally, so assume no requirements
32-
public Dictionary<Guid, int> Save([FromBody] EditSaveDto package, int appId, bool partOfPage)
33-
{
34-
var l = Log.Fn<Dictionary<Guid, int>>($"Items: {package?.Items?.Count}, AppId: {appId}, PartOfPage: {partOfPage}");
35-
return l.ReturnAsOk(Real.Save(package, appId, partOfPage));
36-
}
29+
public async Task<Dictionary<Guid, int>> Save([FromBody] EditSaveDto package, int appId, bool partOfPage) =>
30+
await Real.Save(package, appId, partOfPage);
3731

3832
/// <inheritdoc />
3933
[HttpGet]
4034
[DnnModuleAuthorize(AccessLevel = SecurityAccessLevel.View)]
41-
public LinkInfoDto LinkInfo(string link, int appId, string contentType = default, Guid guid = default,
42-
string field = default)
43-
=> Real.LinkInfo(link, appId, contentType, guid, field);
35+
public LinkInfoDto LinkInfo(string link, int appId, string contentType = default, Guid guid = default, string field = default) =>
36+
Real.LinkInfo(link, appId, contentType, guid, field);
4437

4538
/// <inheritdoc />
4639
[HttpPost]
4740
[DnnModuleAuthorize(AccessLevel = SecurityAccessLevel.View)]
48-
public bool Publish(int id)
49-
=> Real.Publish(id);
41+
public bool Publish(int id) =>
42+
Real.Publish(id);
5043
}

Src/Dnn/ToSic.Sxc.Dnn.WebApi/Dnn/WebApi/Sys/ControllerBase/DynamicApiCompileCodeHelpers.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,32 @@ public void InitializeBlockContext(HttpRequestMessage request)
5454
Log.A($"HasBlock: {block != null}");
5555

5656
var services = _sysHlp.GetService<ApiControllerDependencies>().ConnectServices(Log);
57-
var codeRoot = services.ExCtxFactory
58-
.New(_owner, block, Log, compatibilityFallback: CompatibilityLevels.CompatibilityLevel10);
57+
var exCtx = services.ExCtxFactory.New(new()
58+
{
59+
OwnerOrNull = _owner,
60+
BlockOrNull = block,
61+
ParentLog = Log,
62+
CompatibilityFallback = CompatibilityLevels.CompatibilityLevel10,
63+
});
5964

60-
_sysHlp.ConnectToRoot(codeRoot);
65+
_sysHlp.ConnectToRoot(exCtx);
6166

62-
AdamCode = codeRoot.GetService<AdamCode>();
67+
AdamCode = exCtx.GetService<AdamCode>();
6368

6469
// In case SxcBlock was null, there is no instance, but we may still need the app
65-
var app = codeRoot.GetApp();
70+
var app = exCtx.GetApp();
6671
if (app == null! /* Special: there are cases where it's null, even though the API doesn't show it */)
6772
{
6873
Log.A("DynCode.App is null");
6974
app = GetAppOrNullFromUrlParams(services, request);
7075
if (app != null)
71-
((IExCtxAttachApp)codeRoot).AttachApp(app);
76+
((IExCtxAttachApp)exCtx).AttachApp(app);
7277
}
7378

7479
var reqProperties = request.Properties;
7580

7681
// must run this after creating AppAndDataHelpers
77-
reqProperties.Add(DnnConstants.DnnContextKey, (codeRoot as IHasDnn)?.Dnn);
82+
reqProperties.Add(DnnConstants.DnnContextKey, (exCtx as IHasDnn)?.Dnn);
7883

7984
/*if (*/
8085
reqProperties.TryGetTyped(SourceCodeConstants.SharedCodeRootPathKeyInCache, out string path);
@@ -85,7 +90,7 @@ public void InitializeBlockContext(HttpRequestMessage request)
8590
_sysHlp.WebApiLogging?.AddLogSpecs(block, app, currentPath, _sysHlp.GetService<CodeInfosInScope>());
8691

8792

88-
return (codeRoot, path);
93+
return (exCtx, path);
8994
}
9095

9196

Src/Dnn/ToSic.Sxc.Dnn/DnnPackageBuilder/ReleaseNotes.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p>
2-
<b>2sxc v21.02.00</b>
2+
<b>2sxc v21.03.00</b>
33
<br><br>
44
Note: 2sxc v20 cleans up a lot of old APIs, so it's called a <a href="https://go.2sxc.org/mot">MoT release</a> (Moment of Truth).
55
<br><br>

0 commit comments

Comments
 (0)