This repository has been archived by the owner on Dec 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite of use of UmbracoContext & ApplicationContext (See description)
Based on the idea of https://github.com/umbraco/Umbraco-CMS/blob/release-7.3.2/src/Umbraco.Web/IUmbracoContextAccessor.cs & https://github.com/umbraco/Umbraco-CMS/blob/release-7.3.2/src/Umbraco.Web/SingletonUmbracoContextAccessor.cs I've implemented an "UmbracoApplicationContextAccessor which allows readonly access to the UmbracoContext & ApplicationContext. In most cases this will use the SingletonUmbracoApplicationContextAccessor but in the case of tests there is a publicly available static register method to setup an alternative which used a mocked version of this accessor. Not happy about the accessor being passed through so many properties but it's the best way I can think of to ensure we're using exactly the same contexts from method to method.
- Loading branch information
1 parent
e25d132
commit bd4c79a
Showing
7 changed files
with
106 additions
and
32 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/Our.Umbraco.Ditto/Common/UmbracoApplicationContextAccessor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Umbraco.Core; | ||
using Umbraco.Web; | ||
|
||
namespace Our.Umbraco.Ditto | ||
{ | ||
/// <summary> | ||
/// An interface allowing access to the UmbracoContext & ApplicationContext without resulting to using the singletons directly. | ||
/// </summary> | ||
public interface IUmbracoApplicationContextAccessor | ||
{ | ||
/// <summary> | ||
/// The UmbracoContext instance. | ||
/// </summary> | ||
UmbracoContext UmbracoContext { get; } | ||
|
||
/// <summary> | ||
/// The ApplicationContext instance. | ||
/// </summary> | ||
ApplicationContext ApplicationContext { get; } | ||
} | ||
|
||
internal class SingletonUmbracoApplicationContextAccessor : IUmbracoApplicationContextAccessor | ||
{ | ||
public UmbracoContext UmbracoContext | ||
{ | ||
get | ||
{ | ||
return UmbracoContext.Current; | ||
} | ||
} | ||
|
||
public ApplicationContext ApplicationContext | ||
{ | ||
get | ||
{ | ||
return ApplicationContext.Current; | ||
} | ||
} | ||
} | ||
} |
1 change: 0 additions & 1 deletion
1
src/Our.Umbraco.Ditto/ComponentModel/Attributes/DittoMultiProcessorAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Our.Umbraco.Ditto | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters