I am working on a C # project that sits on top of a third-party CMS. The team uses Injection Dependency to facilitate loose coupling between classes.
I need to "extend" the CMS apis with common functions that are used on several pages.
Interestingly, these common functions have several dependencies.
In this case, is it more expedient to extend this functionality using static extension methods or by creating new interfaces?
Context
Say a third party has two interfaces IContentLoaderand IPageSecuritythat work with objects Page:
namespace 3rdParty.Api
{
public class Page{}
public interface IContentLoader{
T LoadItem<T>(Guid id) where T : Page;
}
public interface IPageSecurity
{
bool CurrentUserCanReadPage(Page p);
}
}
And I want to write a general method, for example:
public IEnumerable<T> LoadAllChildPagesTheUserCanRead(Guid id) where T:Page
{
}
( , )
Property Injection:
public static class IContentLoaderExtensions
{
public static Injected<IPageSecurity> PageSecurity {get;set;}
public static IEnumerable<T> LoadAllChildItems(
this IContentLoader contentLoader, Guid id){}
}
, IContentLoader, . , , Property Injection , , , .
, Wrapper:
public class AdvancedContentLoader
{
public AdvancedContentLoader(IContentLoader c, IPageSecurity p){
}
IEnumerable<T> LoadAllChildItems(Guid id){}
}
, , . , AdvancedContentLoader IContentLoader, .
, , - Property Injection? , - , ?