Skip to content

Commit

Permalink
Created IApplicationInfo and IApplicationStatusInfo for Dependency In…
Browse files Browse the repository at this point in the history
…jection (#3988)

* Created IApplicationInfo and IApplicationStatusInfo interfaces and marked related global apis as deprecated
* Adjusted global methods that needed to use new way of handling application status via IApplicationStatusInfo
* Added INotifyPropertyChanged to the LazyServiceProvider this allow Globals to listen for when the provider is set and update any dependencies in the Globals class
* Updated global to immediately resolve dependencies if it doesn't implement INotifyPropertyChanged (useful for unit testing). Updated unit tests to mock out IApplicationStatusInfo
* Updated navigation manager to follow same pattern as ApplicationStatusInfo and resolve it only once

Co-authored-by: Brian Dukes <bdukes@engagesoftware.com>
  • Loading branch information
SkyeHoefling and bdukes committed Aug 19, 2020
1 parent 0bd8b22 commit a2317ae
Show file tree
Hide file tree
Showing 43 changed files with 2,397 additions and 1,715 deletions.
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)));
}
}
}
Loading

0 comments on commit a2317ae

Please sign in to comment.