Skip to content

Commit

Permalink
Merge pull request #24 from Kentico/streamlining-di
Browse files Browse the repository at this point in the history
Streamlines DI by letting base classes implement appropriate interfaces. Also moves and renames CultureRepository to CultureService and ICultureService respectivelyDictionary
  • Loading branch information
lukas-xb authored Mar 21, 2019
2 parents 994dfd6 + a32b4ce commit 1b332e0
Show file tree
Hide file tree
Showing 24 changed files with 44 additions and 35 deletions.
5 changes: 3 additions & 2 deletions Business/Business.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@
<Compile Include="Repository\Company\ICompanyServiceRepository.cs" />
<Compile Include="Repository\Contact\ContactSectionRepository.cs" />
<Compile Include="Repository\Contact\IContactSectionRepository.cs" />
<Compile Include="Repository\Culture\CultureRepository.cs" />
<Compile Include="Repository\Culture\ICultureRepository.cs" />
<Compile Include="Services\Culture\CultureService.cs" />
<Compile Include="Services\Culture\ICultureService.cs" />
<Compile Include="Repository\Doctor\DoctorRepository.cs" />
<Compile Include="Repository\Doctor\DoctorSectionRepository.cs" />
<Compile Include="Repository\Doctor\IDoctorRepository.cs" />
Expand All @@ -567,6 +567,7 @@
<Compile Include="Repository\Menu\MenuRepository.cs" />
<Compile Include="Repository\Social\ISocialLinkRepository.cs" />
<Compile Include="Repository\Social\SocialLinkRepository.cs" />
<Compile Include="Services\BaseService.cs" />
<Compile Include="Services\Cache\CacheDependencyType.cs" />
<Compile Include="Services\Cache\CacheService.cs" />
<Compile Include="Services\Cache\ICacheService.cs" />
Expand Down
8 changes: 4 additions & 4 deletions Business/DependencyInjection/BusinessDependencies.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
using Business.Repository.Company;
using Business.Repository.Culture;
using Business.Repository.Menu;
using Business.Repository.Social;
using Business.Services.Cache;
using Business.Services.Context;
using Business.Services.Culture;

namespace Business.DependencyInjection
{
public class BusinessDependencies : IBusinessDependencies
{
public IMenuRepository MenuRepository { get; }
public ICompanyRepository CompanyRepository { get; }
public ICultureRepository CultureRepository { get; }
public ICultureService CultureService { get; }
public ISiteContextService SiteContextService { get; }
public ISocialLinkRepository SocialLinkRepository { get; }
public ICacheService CacheService { get; }

public BusinessDependencies(
IMenuRepository menuRepository,
ICompanyRepository companyRepository,
ICultureRepository cultureRepository,
ICultureService cultureService,
ISiteContextService siteContextService,
ISocialLinkRepository socialLinkRepository,
ICacheService cacheDependencyService
)
{
MenuRepository = menuRepository;
CompanyRepository = companyRepository;
CultureRepository = cultureRepository;
CultureService = cultureService;
SiteContextService = siteContextService;
SocialLinkRepository = socialLinkRepository;
CacheService = cacheDependencyService;
Expand Down
4 changes: 2 additions & 2 deletions Business/DependencyInjection/IBusinessDependencies.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Business.Repository.Company;
using Business.Repository.Culture;
using Business.Repository.Menu;
using Business.Repository.Social;
using Business.Services.Cache;
using Business.Services.Context;
using Business.Services.Culture;

namespace Business.DependencyInjection
{
public interface IBusinessDependencies
{
IMenuRepository MenuRepository { get; }
ICompanyRepository CompanyRepository { get; }
ICultureRepository CultureRepository { get; }
ICultureService CultureService { get; }
ISiteContextService SiteContextService { get; }
ISocialLinkRepository SocialLinkRepository { get; }
ICacheService CacheService { get; }
Expand Down
2 changes: 1 addition & 1 deletion Business/Repository/BaseRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Business.Repository
{
public abstract class BaseRepository
public abstract class BaseRepository: IRepository
{
protected IDocumentQueryService DocumentQueryService { get; }

Expand Down
2 changes: 1 addition & 1 deletion Business/Repository/Company/ICompanyRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Business.Repository.Company
{
public interface ICompanyRepository : IRepository
public interface ICompanyRepository
{
CompanyDto GetCompany();
}
Expand Down
2 changes: 1 addition & 1 deletion Business/Repository/Company/ICompanyServiceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Business.Repository.Company
{
public interface ICompanyServiceRepository : IRepository
public interface ICompanyServiceRepository
{
IEnumerable<CompanyServiceDto> GetCompanyServices();
}
Expand Down
2 changes: 1 addition & 1 deletion Business/Repository/Contact/IContactSectionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Business.Repository.Contact
{
public interface IContactSectionRepository : IRepository
public interface IContactSectionRepository
{
ContactSectionDto GetContactSection();
}
Expand Down
2 changes: 1 addition & 1 deletion Business/Repository/Doctor/IDoctorRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Business.Repository.Doctor
{
public interface IDoctorRepository : IRepository
public interface IDoctorRepository
{
IEnumerable<DoctorDto> GetDoctors();
DoctorDto GetDoctor(Guid nodeGuid);
Expand Down
2 changes: 1 addition & 1 deletion Business/Repository/Doctor/IDoctorSectionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Business.Repository.Doctor
{
public interface IDoctorSectionRepository : IRepository
public interface IDoctorSectionRepository
{
DoctorSectionDto GetDoctorSection();
}
Expand Down
2 changes: 1 addition & 1 deletion Business/Repository/Home/IHomeSectionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Business.Repository.Home
{
public interface IHomeSectionRepository : IRepository
public interface IHomeSectionRepository
{
HomeSectionDto GetHomeSection();
}
Expand Down
2 changes: 1 addition & 1 deletion Business/Repository/Map/IMapRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Business.Repository.Map
{
public interface IMapRepository : IRepository
public interface IMapRepository
{
IEnumerable<MapLocationDto> GetOfficeLocations();
}
Expand Down
2 changes: 1 addition & 1 deletion Business/Repository/Menu/IMenuRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Business.Repository.Menu
{
public interface IMenuRepository : IRepository
public interface IMenuRepository
{
IEnumerable<MenuItemDto> GetMenuItems();
}
Expand Down
2 changes: 1 addition & 1 deletion Business/Repository/Social/ISocialLinkRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Business.Repository.Social
{
public interface ISocialLinkRepository : IRepository
public interface ISocialLinkRepository
{
IEnumerable<SocialLinkDto> GetSocialLinks();
}
Expand Down
7 changes: 7 additions & 0 deletions Business/Services/BaseService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

namespace Business.Services
{
public abstract class BaseService : IService
{
}
}
2 changes: 1 addition & 1 deletion Business/Services/Cache/CacheService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Business.Services.Cache
{
public class CacheService : ICacheService
public class CacheService : BaseService, ICacheService
{
public ISiteContextService SiteContextService { get; }

Expand Down
2 changes: 1 addition & 1 deletion Business/Services/Cache/ICacheService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Business.Services.Cache
{
public interface ICacheService : IService
public interface ICacheService
{
/// <summary>
/// Gets nodes cache dependency key for any given type and action
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
using System.Collections.Generic;
using System.Linq;
using CMS.SiteProvider;
using Business.Dto.Culture;
using Business.Services.Context;
using CMS.SiteProvider;

namespace Business.Repository.Culture
namespace Business.Services.Culture
{
public class CultureRepository : ICultureRepository
public class CultureService : BaseService, ICultureService
{
private ISiteContextService SiteContextService { get; }

public CultureRepository(ISiteContextService siteContextService)
public CultureService(ISiteContextService siteContextService)
{
SiteContextService = siteContextService;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Collections.Generic;
using Business.Dto.Culture;

namespace Business.Repository.Culture
namespace Business.Services.Culture
{
public interface ICultureRepository : IRepository
public interface ICultureService
{
IEnumerable<CultureDto> GetSiteCultures();
}
Expand Down
2 changes: 1 addition & 1 deletion Business/Services/MediaLibrary/IMediaLibraryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Business.Services.MediaLibrary
{
public interface IMediaLibraryService : IService
public interface IMediaLibraryService
{
/// <summary>
/// Wrapper around Kentico API for retrieving media stored in media libraries.
Expand Down
2 changes: 1 addition & 1 deletion Business/Services/MediaLibrary/MediaLibraryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Business.Services.MediaLibrary
{
public class MediaLibraryService : IMediaLibraryService
public class MediaLibraryService : BaseService, IMediaLibraryService
{
public IEnumerable<MediaLibraryFileDto> GetMediaLibraryFiles(string folder, string sitename, params string[] extensions)
{
Expand Down
4 changes: 2 additions & 2 deletions Business/Services/Query/DocumentQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

namespace Business.Services.Query
{
public class DocumentQueryService : IDocumentQueryService
public class DocumentQueryService : BaseService, IDocumentQueryService
{
private ISiteContextService SiteContext { get; }

private readonly string[] _coreColumns =
{
//Defines initial columns returned for optimization. If not set, all columns are returned.
// Defines initial columns returned for optimization. If not set, all columns are returned.
"NodeGUID", "DocumentID", "NodeID"
};

Expand Down
2 changes: 1 addition & 1 deletion Business/Services/Query/IDocumentQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Business.Services.Query
{
public interface IDocumentQueryService : IService
public interface IDocumentQueryService
{
/// <summary>
/// Wrapper around Kentico's DocumentQuery.
Expand Down
4 changes: 2 additions & 2 deletions MedioClinic/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public PageViewModel GetPageViewModel(string title)
MenuItems = Dependencies.MenuRepository.GetMenuItems() ?? new List<MenuItemDto>(),
Metadata = GetPageMetadata(title),
Company = GetCompany(),
Cultures = Dependencies.CultureRepository.GetSiteCultures(),
Cultures = Dependencies.CultureService.GetSiteCultures(),
SocialLinks = GetSocialLinks(),
};
}
Expand All @@ -36,7 +36,7 @@ public PageViewModel<TViewModel> GetPageViewModel<TViewModel>(TViewModel data, s
MenuItems = Dependencies.MenuRepository.GetMenuItems() ?? new List<MenuItemDto>(),
Metadata = GetPageMetadata(title),
Company = GetCompany(),
Cultures = Dependencies.CultureRepository.GetSiteCultures(),
Cultures = Dependencies.CultureService.GetSiteCultures(),
SocialLinks = GetSocialLinks(),
Data = data
};
Expand Down
5 changes: 3 additions & 2 deletions MedioClinic/Utils/SiteContextService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using Business.Services.Context;
using Business.Services;
using Business.Services.Context;
using Kentico.Content.Web.Mvc;
using Kentico.Web.Mvc;

namespace MedioClinic.Utils
{
public class SiteContextService : ISiteContextService
public class SiteContextService : BaseService, ISiteContextService
{
public string SiteName { get; }

Expand Down

0 comments on commit 1b332e0

Please sign in to comment.