Skip to content

Commit 4bb08b5

Browse files
committed
Merge branch 'data-provided-property' of https://github.com/valadas/Dnn.Platform into data-provided-property
2 parents 76dc3de + 854a61d commit 4bb08b5

10 files changed

Lines changed: 76 additions & 40 deletions

File tree

DNN Platform/DotNetNuke.Web.Client.ResourceManager/ClientResourceController.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,12 @@ public string RenderDependencies(ResourceType resourceType, string provider, str
241241

242242
var ext = Path.GetExtension(resource.ResolvedPath);
243243
var rtlResolvedPath = Path.ChangeExtension(resource.ResolvedPath, ".rtl" + ext);
244-
if (!File.Exists(this.appStatus.ApplicationMapPath + rtlResolvedPath))
244+
var cleanRtlResolvedPath = rtlResolvedPath.TrimStart('~').Replace("/", "\\");
245+
var physicalPath = Path.Combine(
246+
this.appStatus.ApplicationMapPath,
247+
cleanRtlResolvedPath.TrimStart('\\'));
248+
249+
if (!File.Exists(physicalPath))
245250
{
246251
return resource;
247252
}

DNN Platform/DotNetNuke.Web/Common/DotNetNukeHttpApplication.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,8 @@ static DotNetNukeHttpApplication()
5252
{
5353
var dependencyProvider = new LazyServiceProvider();
5454
Globals.DependencyProvider = dependencyProvider;
55-
dependencyProvider.SetProvider(DependencyInjectionInitialize.BuildServiceProvider());
56-
ServiceRequestScopeModule.SetServiceProvider(Globals.DependencyProvider);
57-
HttpRuntime.WebObjectActivator = new WebFormsServiceProvider();
5855

59-
ComponentFactory.Container = new ContainerWithServiceProviderFallback(new SimpleContainer(), Globals.DependencyProvider);
56+
ComponentFactory.Container = new ContainerWithServiceProviderFallback(new SimpleContainer(Globals.DependencyProvider), Globals.DependencyProvider);
6057

6158
ComponentFactory.InstallComponents(new ProviderInstaller("databaseConnection", typeof(DatabaseConnectionProvider), typeof(SqlDatabaseConnectionProvider)));
6259
ComponentFactory.InstallComponents(new ProviderInstaller("data", typeof(DataProvider), typeof(SqlDataProvider)));
@@ -85,6 +82,10 @@ static DotNetNukeHttpApplication()
8582
#pragma warning restore CS0618 // Type or member is obsolete
8683
ComponentFactory.InstallComponents(new ProviderInstaller("tokens", typeof(TokenProvider)));
8784
ComponentFactory.InstallComponents(new ProviderInstaller("mail", typeof(MailProvider)));
85+
86+
dependencyProvider.SetProvider(DependencyInjectionInitialize.BuildServiceProvider());
87+
ServiceRequestScopeModule.SetServiceProvider(Globals.DependencyProvider);
88+
HttpRuntime.WebObjectActivator = new WebFormsServiceProvider();
8889
}
8990

9091
private static void RegisterIfNotAlreadyRegistered<TConcrete>()

DNN Platform/DotNetNuke.Web/Common/LazyServiceProvider.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ public class LazyServiceProvider : IServiceProvider, INotifyPropertyChanged
1818
/// <inheritdoc />
1919
public object GetService(Type serviceType)
2020
{
21-
if (this.serviceProvider is null)
22-
{
23-
throw new InvalidOperationException("Cannot resolve services until the service provider is built.");
24-
}
25-
26-
return this.serviceProvider.GetService(serviceType);
21+
return this.serviceProvider?.GetService(serviceType);
2722
}
2823

2924
/// <summary>Sets the service provider.</summary>

DNN Platform/Library/ComponentModel/ComponentFactory.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ namespace DotNetNuke.ComponentModel
77
using System.Collections;
88
using System.Collections.Generic;
99

10+
using DotNetNuke.Instrumentation;
11+
1012
public static class ComponentFactory
1113
{
14+
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(ComponentFactory));
15+
1216
public static IContainer Container { get; set; }
1317

1418
public static void InstallComponents(params IComponentInstaller[] installers)
@@ -200,6 +204,7 @@ private static void VerifyContainer()
200204
{
201205
if (Container == null)
202206
{
207+
Logger.Warn("Container was null, instantiating SimpleContainer");
203208
Container = new SimpleContainer();
204209
}
205210
}

DNN Platform/Library/ComponentModel/ContainerWithServiceProviderFallback.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ namespace DotNetNuke.ComponentModel;
66
using System;
77
using System.Collections;
88

9+
using DotNetNuke.Instrumentation;
10+
911
using Microsoft.Extensions.DependencyInjection;
1012

1113
/// <summary>A container which gets components from an <see cref="IServiceProvider"/> for components not registered.</summary>
1214
public class ContainerWithServiceProviderFallback : IContainer
1315
{
16+
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(ContainerWithServiceProviderFallback));
1417
private readonly IContainer container;
1518
private readonly IServiceProvider serviceProvider;
1619

@@ -115,7 +118,18 @@ public object GetComponent(string name)
115118

116119
/// <inheritdoc />
117120
public TContract GetComponent<TContract>()
118-
=> this.container.GetComponent<TContract>() ?? this.serviceProvider.GetService<TContract>();
121+
{
122+
Logger.Trace($"Getting component for {typeof(TContract).FullName}");
123+
var service = this.container.GetComponent<TContract>();
124+
if (service is not null)
125+
{
126+
Logger.Trace($"Got component for {typeof(TContract).FullName} from container");
127+
return service;
128+
}
129+
130+
Logger.Trace($"Getting component for {typeof(TContract).FullName} from service provider");
131+
return this.serviceProvider.GetService<TContract>();
132+
}
119133

120134
/// <inheritdoc />
121135
public TContract GetComponent<TContract>(string name)

DNN Platform/Library/ComponentModel/IComponentBuilder.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information
44

5-
namespace DotNetNuke.ComponentModel
6-
{
7-
public interface IComponentBuilder
8-
{
9-
string Name { get; }
10-
11-
object BuildComponent();
12-
}
13-
}
5+
namespace DotNetNuke.ComponentModel
6+
{
7+
public interface IComponentBuilder
8+
{
9+
string Name { get; }
10+
11+
object BuildComponent();
12+
}
13+
}

DNN Platform/Library/ComponentModel/SimpleContainer.cs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,51 @@ namespace DotNetNuke.ComponentModel
99
using System.Diagnostics.CodeAnalysis;
1010

1111
using DotNetNuke.Collections.Internal;
12+
using DotNetNuke.Common;
1213

1314
public class SimpleContainer : AbstractContainer, IDisposable
1415
{
1516
private readonly string name;
17+
private readonly IServiceProvider serviceProvider;
1618
private readonly ComponentBuilderCollection componentBuilders = new ComponentBuilderCollection();
17-
1819
private readonly SharedDictionary<string, IDictionary> componentDependencies = new SharedDictionary<string, IDictionary>();
19-
2020
private readonly ComponentTypeCollection componentTypes = new ComponentTypeCollection();
21-
2221
private readonly SharedDictionary<Type, string> registeredComponents = new SharedDictionary<Type, string>();
2322

2423
/// <summary>Initializes a new instance of the <see cref="SimpleContainer"/> class.</summary>
24+
[Obsolete("Deprecated in DotNetNuke 10.2.2. Please use overload with IServiceProvider. Scheduled removal in v12.0.0.")]
2525
public SimpleContainer()
26-
: this($"Container_{Guid.NewGuid()}")
26+
: this(Globals.DependencyProvider)
27+
{
28+
}
29+
30+
/// <summary>Initializes a new instance of the <see cref="SimpleContainer"/> class.</summary>
31+
/// <param name="serviceProvider">The DI container scope.</param>
32+
public SimpleContainer(IServiceProvider serviceProvider)
33+
: this($"Container_{Guid.NewGuid()}", serviceProvider)
2734
{
2835
}
2936

3037
/// <summary>Initializes a new instance of the <see cref="SimpleContainer"/> class.</summary>
3138
/// <param name="name">The container name.</param>
39+
[Obsolete("Deprecated in DotNetNuke 10.2.2. Please use overload with IServiceProvider. Scheduled removal in v12.0.0.")]
3240
public SimpleContainer(string name)
41+
: this(name, Globals.DependencyProvider)
3342
{
34-
this.name = name;
3543
}
3644

37-
/// <inheritdoc />
38-
public override string Name
45+
/// <summary>Initializes a new instance of the <see cref="SimpleContainer"/> class.</summary>
46+
/// <param name="name">The container name.</param>
47+
/// <param name="serviceProvider">The DI container scope.</param>
48+
public SimpleContainer(string name, IServiceProvider serviceProvider)
3949
{
40-
get
41-
{
42-
return this.name;
43-
}
50+
this.name = name;
51+
this.serviceProvider = serviceProvider;
4452
}
4553

54+
/// <inheritdoc />
55+
public override string Name => this.name;
56+
4657
/// <inheritdoc />
4758
[SuppressMessage("Microsoft.Naming", "CA1725:ParameterNamesShouldMatchBaseDeclaration", Justification = "Breaking change")]
4859
public override void RegisterComponent(string name, Type type)
@@ -144,10 +155,10 @@ public override void RegisterComponent(string name, Type contractType, Type type
144155
switch (lifestyle)
145156
{
146157
case ComponentLifeStyleType.Transient:
147-
builder = new TransientComponentBuilder(name, type);
158+
builder = new TransientComponentBuilder(this.serviceProvider, name, type);
148159
break;
149160
case ComponentLifeStyleType.Singleton:
150-
builder = new SingletonComponentBuilder(name, type);
161+
builder = new SingletonComponentBuilder(this.serviceProvider, name, type);
151162
break;
152163
}
153164

DNN Platform/Library/ComponentModel/SingletonComponentBuilder.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@ namespace DotNetNuke.ComponentModel
99

1010
internal class SingletonComponentBuilder : IComponentBuilder
1111
{
12+
private readonly IServiceProvider serviceProvider;
1213
private readonly Type type;
1314
private object instance;
1415

1516
/// <summary>Initializes a new instance of the <see cref="SingletonComponentBuilder"/> class.</summary>
17+
/// <param name="serviceProvider">The DI container scope.</param>
1618
/// <param name="name">The name of the component.</param>
1719
/// <param name="type">The type of the component.</param>
18-
public SingletonComponentBuilder(string name, Type type)
20+
public SingletonComponentBuilder(IServiceProvider serviceProvider, string name, Type type)
1921
{
2022
this.Name = name;
23+
this.serviceProvider = serviceProvider;
2124
this.type = type;
2225
}
2326

@@ -27,7 +30,7 @@ public SingletonComponentBuilder(string name, Type type)
2730
/// <inheritdoc />
2831
public object BuildComponent()
2932
{
30-
return this.instance ??= Reflection.CreateObject(this.type);
33+
return this.instance ??= Reflection.CreateObject(this.serviceProvider, this.type);
3134
}
3235
}
3336
}

DNN Platform/Library/ComponentModel/TransientComponentBuilder.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ namespace DotNetNuke.ComponentModel
55
{
66
using System;
77

8-
using DotNetNuke.Common;
98
using DotNetNuke.Framework;
109

1110
internal class TransientComponentBuilder : IComponentBuilder
1211
{
12+
private readonly IServiceProvider serviceProvider;
1313
private readonly Type type;
1414

1515
/// <summary>Initializes a new instance of the <see cref="TransientComponentBuilder"/> class.</summary>
16+
/// <param name="serviceProvider">The DI container scope.</param>
1617
/// <param name="name">The name of the component.</param>
1718
/// <param name="type">The type of the component.</param>
18-
public TransientComponentBuilder(string name, Type type)
19+
public TransientComponentBuilder(IServiceProvider serviceProvider, string name, Type type)
1920
{
2021
this.Name = name;
22+
this.serviceProvider = serviceProvider;
2123
this.type = type;
2224
}
2325

@@ -27,7 +29,7 @@ public TransientComponentBuilder(string name, Type type)
2729
/// <inheritdoc />
2830
public object BuildComponent()
2931
{
30-
return Reflection.CreateObject(this.type);
32+
return Reflection.CreateObject(this.serviceProvider, this.type);
3133
}
3234
}
3335
}

DNN Platform/Library/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void ConfigureServices(IServiceCollection services)
158158
var dataProvider = serviceProvider.GetRequiredService<DataProvider>();
159159
var defaultConnectionStringName = dataProvider.Settings["connectionStringName"];
160160

161-
return new PetaPocoDataContext(defaultConnectionStringName, DataProvider.Instance().ObjectQualifier);
161+
return new PetaPocoDataContext(defaultConnectionStringName, dataProvider.ObjectQualifier);
162162
});
163163

164164
services.AddTransient<ModuleInjectionManager>();

0 commit comments

Comments
 (0)