Skip to content

Instantly share code, notes, and snippets.

@geoffreysmith
geoffreysmith / ControllerWithContext.cs.t4
Created April 10, 2011 14:35
Sharpified controller
<#@ template language="C#" HostSpecific="True" inherits="DynamicTransform" #>
<#@ Output Extension="cs" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ import namespace="EnvDTE" #>
namespace <#= Model.ControllerNamespace #>
{
@geoffreysmith
geoffreysmith / MvcScaffolding.Controller.ps1
Created April 10, 2011 14:48
Got rid of dbcontext, plural controller/view names
[T4Scaffolding.ControllerScaffolder("Controller with read/write action and views, using EF data access code", Description = "Adds an ASP.NET MVC controller with views and data access code", SupportsModelType = $true, SupportsDataContextType = $true, SupportsViewScaffolder = $true)][CmdletBinding()]
param(
[parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)][string]$ControllerName,
[string]$ModelType,
[string]$Project,
[string]$CodeLanguage,
[string]$DbContextType,
[string]$Area,
[string]$ViewScaffolder = "View",
[alias("MasterPage")][string]$Layout,
@geoffreysmith
geoffreysmith / gist:923501
Created April 16, 2011 21:09
AddCustomRepositoriesTo(container);
Could not load type 'System.Func`2' from assembly 'SharpArch, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.TypeLoadException: Could not load type 'System.Func`2' from assembly 'SharpArch, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
@geoffreysmith
geoffreysmith / gist:923505
Created April 16, 2011 21:18
ModelBinder
Could not load type 'System.Func`2' from assembly 'SharpArch, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.TypeLoadException: Could not load type 'System.Func`2' from assembly 'SharpArch, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
// #001 Using Query Objects
namespace SharpArchCookbook.Web.Mvc.Controllers.Queries.Products
{
using Domain;
using MvcContrib.Pagination;
using NHibernate.Transform;
using SharpArch.NHibernate;
using ViewModels;
@geoffreysmith
geoffreysmith / gist:972788
Created May 15, 2011 00:57
Query dependency injection
private static void AddApplicationServicesTo(IWindsorContainer container)
{
container.Register(
AllTypes
.FromAssemblyNamed("SharpArchCookbook.Tasks")
.Pick()
.WithService.FirstInterface());
}
private static void AddQueriesTo(IWindsorContainer container)
@geoffreysmith
geoffreysmith / gist:1006489
Created June 3, 2011 15:08
Simple SharpArch repo demo
// Business object living in the Domain layer
public class Project : Entity
{
public virtual string Name { get; set; }
}
// Controller
public class HomeController : Controller
{
@geoffreysmith
geoffreysmith / gist:1118349
Created August 1, 2011 15:29
simplecqrs createcommand
public abstract class CreateCommandHandler<TCommand> : CommandHandler<TCommand> where TCommand : ICommand
{
public override void Handle(TCommand command)
{
var aggregateRoot = CreateAggregateRoot(command);
Handle(command, aggregateRoot);
var domainRepository = ServiceLocator.Current.Resolve<IDomainRepository>();
@geoffreysmith
geoffreysmith / gist:1264520
Created October 5, 2011 14:12
TempDataExtensions
public static class TempDataExtension
{
public static void Put(this TempDataDictionary tempData, string key, object value)
{
var js = new JavaScriptSerializer();
tempData[key] = js.Serialize(value);
}
public static T Get<T>(this TempDataDictionary tempData, string key) where T : class
{
@geoffreysmith
geoffreysmith / gist:1264524
Created October 5, 2011 14:13
TempDataextensionsUsage
var car = new Car
{
Make = "Toyota",
AWD = true
};
TempData.Put("Automobile", car);
TempData.Get<Motorcycle>("Automobile")