Sitecore TDD with Glass
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
using System; | |
using System.Reflection; | |
using System.Web.Mvc; | |
using Autofac; | |
using Autofac.Integration.Mvc; | |
using Glass.Mapper.Sc; | |
namespace AutofacDemo | |
{ | |
public class AutofacConfig | |
{ | |
public static void RegisterAutofac() | |
{ | |
var builder = new ContainerBuilder(); | |
// Register MVC controllers. | |
builder.RegisterControllers(Assembly.GetExecutingAssembly()); | |
// Register repositories | |
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()) | |
.Where(t => t.Name.ToLower().EndsWith("repository")) | |
.AsImplementedInterfaces(); | |
// Register Glass SitecoreContext | |
builder.RegisterType<SitecoreContext>().As<ISitecoreContext>(); | |
// Set the dependency resolver to be Autofac. | |
var container = builder.Build(); | |
DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); | |
} | |
} | |
} |
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
<%@ Application Language='C#' Inherits="Sitecore.Web.Application" %> | |
<%@ Import Namespace="System.Web.Optimization" %> | |
<%@ Import Namespace="AutofacDemo" %> | |
<%@ Import Namespace="GlassDemo" %> | |
<script Language="c#" RunAt="server"> | |
public void Application_Start() | |
{ | |
BundleConfig.RegisterBundles(BundleTable.Bundles); | |
AutofacConfig.RegisterAutofac(); | |
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); | |
} | |
</script> |
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
using System.Collections.Generic; | |
namespace GlassDemo.Models | |
{ | |
public interface ISampleItem | |
{ | |
IEnumerable<ISampleItem> Children { get; set; } | |
string Name { get; set; } | |
string Url { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment