Skip to content

Instantly share code, notes, and snippets.

🐻
Learning...

Sean G. Wright seangwright

🐻
Learning...
Block or report user

Report or block seangwright

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@seangwright
seangwright / DependencyResolverConfig.cs
Last active Jun 3, 2019
Kentico 12: Design Patterns Part 4 - Adding Dependency Injection to the CMS
View DependencyResolverConfig.cs
public static class DependencyResolverConfig
{
public static IContainer BuildContainer()
{
var builder = new ContainerBuilder();
// My registration classes use a "fluent" interface, always returning the ContainerBuilder
// so the next call can be chained off the previous
var container = builder
.RegisterApplicationTypes()
View Kentico12-TipsTricks-Structure-ProductsController.cs
public class ProductsController : Controller
{
private readonly IProductsQuery productsQuery;
private readonly IProductDetailQuery productDetailQuery;
public ProductsController(
IProductsQuery productsQuery,
IProductDetailQuery productDetailQuery)
{
// ...
View Kentico12-TipsTricks-Structure-RouteConfig.cs
/// DependencyConfiguration.cs
/// --------------------------
// ContainerBuilder builder from Autofac
builder.RegisterAssemblyTypes(assemblies)
.Where(t => t.IsClass && !t.IsAbstract && t.Name.EndsWith("RouteRegistry"))
.AsImplementedInterfaces();
/// RouteConfig.cs
/// --------------
View Kentico12-TipsTricks-Structure-RouteCollectionExtensions.cs
public static class RouteCollectionExtensions
{
public static void MapRoute<T>(
this RouteCollection routes,
string name,
string url,
Func<T, string> nameOfDefaultAction) where T : Controller
{
string controller = typeof(T).RemoveControllerSuffix();
string action = nameOfDefaultAction(default);
View Kentico12-TipsTricks-Structure-HomeRouteRegistry.cs
public class HomeRouteRegistry : IRouteRegistry
{
public int Priority => RoutePriorityReference.LOWEST;
public void RegisterRoutes(RouteCollection routes) =>
routes.MapRoute<HomeController>(
name: "Home",
url: "",
nameOfDefaultAction: c => nameof(c.Index)
);
View Kentico12-TipsTricks-Structure-IRouteRegistry.cs
/// <summary>
/// Sourced from https://benfoster.io/blog/improving-aspnet-mvc-routing-configuration
/// </summary>
public interface IRouteRegistry
{
/// <summary>
/// Provides the global <see cref="RouteCollection"/> to which the Registery's routes
/// should be added
/// </summary>
/// <param name="routes"></param>
View Kentico12-TipsTricks-Structure-RouteConfig.cs
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
View Kentico12-Writing-Unit-Tests-AutoDomainDataAttribute.cs
/// <summary>
/// Sourced from https://tech.trailmax.info/2014/01/convert-your-projects-from-nunitmoq-to-xunit-with-nsubstitute/
/// </summary>
public class AutoDomainDataAttribute : AutoDataAttribute
{
public AutoDomainDataAttribute()
: base(() => new Fixture().Customize(new AutoNSubstituteCustomization()))
{ }
}
View Kentico12-Writing-Unit-Tests-SettingInfoProviderFixture.cs
public class SettingInfoProviderFixture : AutomatedTestsWithData
{
/// <summary>
/// Creates a fake SiteInfo
/// </summary>
/// <param name="siteId"></param>
/// <param name="siteName"></param>
public void FakeSiteInfo(int siteId, string siteName) =>
Fake<SiteInfo, SiteInfoProvider>().WithData(
new SiteInfo
View Kentico12-Writing-Unit-Tests-KenticoSettingConfigProviderTests-GetString-Test-Explicit.cs
[Test, AutoDomainData]
public void GetString_Will_Return_Site_Setting_Value(
SettingInfoProviderFixture fixture,
ISiteContext siteContext)
{
// Explicitly defined values
string keyName = "key1";
string keyValue = "value1";
string siteName = "testSite";
int siteId = 3;
You can’t perform that action at this time.