Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created IApplicationInfo and IApplicationStatusInfo for Dependency Injection #3988

Merged
merged 19 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a5f14fe
Created IApplicationInfo and IApplicationStatusInfo interfaces and ma…
SkyeHoefling Aug 16, 2020
04513f6
Fixed failing tests
SkyeHoefling Aug 16, 2020
a733773
Fixed more unit tests
SkyeHoefling Aug 16, 2020
90b64f9
Fixed unit tests
SkyeHoefling Aug 16, 2020
a81dd60
Fixed last set of failing tests
SkyeHoefling Aug 16, 2020
e9dc8a6
Added public default constructor which is required for dependency inj…
SkyeHoefling Aug 16, 2020
a3b51b8
Added missing dependency injection registration of IDnnContext
SkyeHoefling Aug 16, 2020
dd68762
Fixed up deprecation message to match doc recommendations; Adjusted g…
SkyeHoefling Aug 16, 2020
f7ec93f
Added INotifyPropertyChanged to the LazyServiceProvider this allow Gl…
SkyeHoefling Aug 16, 2020
6136fa4
Updated global to immediately resolve dependencies if it doesn't impl…
SkyeHoefling Aug 16, 2020
a72aecb
Added mocks for DependencyProvider
SkyeHoefling Aug 16, 2020
dd3453a
Fixed failing unit tests
SkyeHoefling Aug 16, 2020
0180aee
Updated navigation manager to follow same pattern as applicationstatu…
SkyeHoefling Aug 16, 2020
95ebc7a
Added mocks for INavigationManager since it needs to be loaded onts a…
SkyeHoefling Aug 16, 2020
044bf40
Added missing .csproj
SkyeHoefling Aug 16, 2020
477b875
Updated dependency registration
SkyeHoefling Aug 17, 2020
1632371
Added the default protected constructor back into the DotNetNukeConte…
SkyeHoefling Aug 19, 2020
d27bb3e
Updated deprecation notice on protected constructor
SkyeHoefling Aug 19, 2020
d1353db
Updated deprecation notice in Globals.cs to explain on using Dependen…
SkyeHoefling Aug 19, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions DNN Platform/DotNetNuke.Abstractions/Application/IApplicationInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Abstractions.Application
{
using System;

/// <summary>
/// The Application class contains properties that describe the DotNetNuke Application.
/// </summary>
public interface IApplicationInfo
{
/// <summary>
/// Gets the company to which the DotNetNuke application is related.
/// </summary>
/// <value>Fixed result: DotNetNuke Corporation.</value>
string Company { get; }

/// <summary>
/// Gets the version of the currently installed DotNetNuke framework/application
/// Can be prior to Version, if the application is pending to be upgraded.
/// </summary>
/// <value>The version as retreieved from the database version table.</value>
Version CurrentVersion { get; }

/// <summary>
/// Gets the description of the application.
/// </summary>
/// <value>Fixed result: DNN Platform.</value>
string Description { get; }

/// <summary>
/// Gets the help URL related to the DotNetNuke application.
/// </summary>
/// <value>Fixed result: https://dnndocs.com/. </value>
string HelpUrl { get; }

/// <summary>
/// Gets the legal copyright.
/// </summary>
/// <value>Dynamic: DNN Platform is copyright 2002-todays year by .NET Foundation".</value>
string LegalCopyright { get; }

/// <summary>
/// Gets the name of the application.
/// </summary>
/// <value>Fixed result: DNNCORP.CE.</value>
string Name { get; }

/// <summary>
/// Gets the SKU (Stock Keeping Unit).
/// </summary>
/// <value>Fixed result: DNN.</value>
string SKU { get; }

/// <summary>
/// Gets the status of the DotnetNuke application.
/// </summary>
/// <remarks>
/// If the value is not be Stable, you will see the exactly status and version in page's title if allow display beta message in host setting.
/// </remarks>
/// <value>
/// The value can be: None, Alpha, Beta, RC, Stable.
/// </value>
ReleaseMode Status { get; }

/// <summary>
/// Gets the title of the application.
/// </summary>
/// <value>Fixed value: DotNetNuke.</value>
string Title { get; }

/// <summary>
/// Gets the trademark.
/// </summary>
/// <value>Fixed value: DotNetNuke,DNN.</value>
string Trademark { get; }

/// <summary>
/// Gets the type of the application.
/// </summary>
/// <value>Fixed value: Framework.</value>
string Type { get; }

/// <summary>
/// Gets the upgrade URL.
/// </summary>
/// <value>Fixed value: https://dnnplatform.io. </value>
string UpgradeUrl { get; }

/// <summary>
/// Gets the URL of the application.
/// </summary>
/// <value>Fixed value: https://dnncommunity.org.</value>
string Url { get; }

/// <summary>
/// Gets the version of the DotNetNuke framework/application.
/// </summary>
/// <value>The version as retreieved from the Executing assembly.</value>
Version Version { get; }

/// <summary>
/// Determine whether a product specific change is to be applied.
/// </summary>
/// <param name = "productNames">list of product names.</param>
/// <returns>true if product is within list of names.</returns>
/// <remarks>
/// </remarks>
bool ApplyToProduct(string productNames);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Abstractions.Application
{
using System;

/// <summary>
/// The Application Status Info, includes information about installation
/// and database version.
/// </summary>
public interface IApplicationStatusInfo
{
/// <summary>
/// Gets the status of application.
/// </summary>
UpgradeStatus Status { get; }

/// <summary>
/// Gets the application map path.
/// </summary>
/// <value>
/// The application map path.
/// </value>
string ApplicationMapPath { get; }

/// <summary>
/// Gets the database version.
/// </summary>
Version DatabaseVersion { get; }

/// <summary>
/// IsInstalled looks at various file artifacts to determine if DotNetNuke has already been installed.
/// </summary>
/// <returns>true if installed else false.</returns>
/// <remarks>
/// If DotNetNuke has been installed, then we should treat database connection errors as real errors.
/// If DotNetNuke has not been installed, then we should expect to have database connection problems
/// since the connection string may not have been configured yet, which can occur during the installation
/// wizard.
/// </remarks>
bool IsInstalled();

/// <summary>
/// Sets the status.
/// </summary>
/// <param name="status">The status.</param>
void SetStatus(UpgradeStatus status);

/// <summary>
/// Updates the database version.
/// </summary>
/// <param name="version">The version.</param>
void UpdateDatabaseVersion(Version version);

/// <summary>
/// Updates the database version.
/// </summary>
/// <param name="version">The version.</param>
/// <param name="increment">The increment.</param>
void UpdateDatabaseVersionIncrement(Version version, int increment);

/// <summary>
/// Needs documentation.
/// </summary>
/// <param name="version">The version.</param>
/// <returns>true is success else false.</returns>
bool IncrementalVersionExists(Version version);

/// <summary>
/// Get the last application iteration.
/// </summary>
/// <param name="version">The version.</param>
/// <returns>The result.</returns>
int GetLastAppliedIteration(Version version);
}
}
17 changes: 17 additions & 0 deletions DNN Platform/DotNetNuke.Abstractions/Application/IDnnContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Abstractions.Application
{
/// <summary>
/// Defines the context for the environment of the DotNetNuke application.
/// </summary>
public interface IDnnContext
{
/// <summary>
/// Gets get the application.
/// </summary>
IApplicationInfo Application { get; }
}
}
50 changes: 50 additions & 0 deletions DNN Platform/DotNetNuke.Abstractions/Application/ReleaseMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Abstractions.Application
{
/// <summary>
/// The enumeration of release mode.
/// </summary>
/// <value>
/// <list type="bullet">
/// <item>None: Not specified for the current release.</item>
/// <item>Alpha:Alpha release is an opportunity for customers to get an early look at a particular software feature.</item>
/// <item>Beta: Beta release is a mostly completed release,
/// At this point we will have implemented most of the major features planned for a specific release. </item>
/// <item>RC: RC release will be the Stable release if there is no major show-stopping bugs,
/// We have gone through all the major test scenarios and are just running through a final set of regression
/// tests and verifying the packaging.</item>
/// <item>Stable: Stable release is believed to be ready for use,
/// remember that only stable release can be used in production environment.</item>
/// </list>
/// </value>
public enum ReleaseMode
{
/// <summary>
/// Not asssigned
/// </summary>
None = 0,

/// <summary>
/// Alpha release
/// </summary>
Alpha = 1,

/// <summary>
/// Beta release
/// </summary>
Beta = 2,

/// <summary>
/// Release candidate
/// </summary>
RC = 3,

/// <summary>
/// Stable release version
/// </summary>
Stable = 4,
}
}
38 changes: 38 additions & 0 deletions DNN Platform/DotNetNuke.Abstractions/Application/UpgradeStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information

namespace DotNetNuke.Abstractions.Application
{
/// <summary>
/// Enumeration Of Application upgrade status.
/// </summary>
public enum UpgradeStatus
{
/// <summary>
/// The application need update to a higher version.
/// </summary>
Upgrade = 0,

/// <summary>
/// The application need to install itself.
/// </summary>
Install = 1,

/// <summary>
/// The application is normal running.
/// </summary>
None = 2,

/// <summary>
/// The application occur error when running.
/// </summary>
Error = 3,

/// <summary>
/// The application status is unknown,
/// </summary>
/// <remarks>This status should never be returned. its is only used as a flag that Status hasn't been determined.</remarks>
Unknown = 4,
}
}
22 changes: 12 additions & 10 deletions DNN Platform/DotNetNuke.Web/Common/LazyServiceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,30 @@
namespace DotNetNuke.Web.Common
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;

public class LazyServiceProvider : IServiceProvider
public class LazyServiceProvider : IServiceProvider, INotifyPropertyChanged
{
private IServiceProvider _serviceProvider;

private IServiceProvider serviceProvider;

/// <inheritdoc/>
public event PropertyChangedEventHandler PropertyChanged;

/// <inheritdoc/>
public object GetService(Type serviceType)
{
if (this._serviceProvider is null)
if (this.serviceProvider is null)
{
throw new Exception("Cannot resolve services until the service provider is built.");
}

return this._serviceProvider.GetService(serviceType);
return this.serviceProvider.GetService(serviceType);
}

internal void SetProvider(IServiceProvider serviceProvider)
{
this._serviceProvider = serviceProvider;
this.serviceProvider = serviceProvider;
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(serviceProvider)));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added INotifyPropertyChanged here to allow the Globals.cs to listen for an event when the Service Provider is ready for us. Since the Globals.cs is wrapping several Dependency Injection calls as we deprecate methods it is important that it can resolve dependencies once they are available. This is critical when using Globals.cs at startup.

I decided on INotifyPropertyChanged as it is a .NET Standard type and is used in the desktop/mobile space a lot for notifying objects when something has changed. If there is a better option, I am more than happy to change this

}
}
}
Loading