Skip to content

Instantly share code, notes, and snippets.

@randomcodenz
Created January 26, 2011 02:23
Show Gist options
  • Save randomcodenz/796115 to your computer and use it in GitHub Desktop.
Save randomcodenz/796115 to your computer and use it in GitHub Desktop.
// Implementation of this basically looks up the appropriate command handler from a container
// and calls Handle passing the command
public interface ICommandExecutor
{
Guid ExecuteCreate<T>( T createCommand );
void Execute<T>( T command );
}
public interface ICommandHandler<T>
{
void Handle( T command );
}
public interface ICreateCommandHandler<T>
{
Guid Handle( T createCommand );
}
public class CreateSomethingCommandHandler : ICommandHandler<CreateSomethingCommand>
{
public void Handle( CreateSomethingCommand command )
{
var something = new Something( ... );
// Do other bits required like add to repository
// Now we have something.Id but how to get it back to the caller???
}
}
// Implementation basically looks up the appropriate view factory from a container and calls Load passing the input if any
public interface IViewRepository
{
TView Load<TView>();
TView Load<TInput,TView>( TInput input );
}
public interface IViewFactory<TView>
{
TView Load();
}
public interface IViewFactory<TInput,TView>
{
TView Load(TInput input);
}
public class SomeController : Controller
{
private readonly IViewRepository _views;
private readonly ICommandExecutor _commandExecutor;
public ActionResult DoSomething( SomeNewForm theForm )
{
if( !Model.IsValid )
{
return View();
}
_commandExecutor.Execute( new CreateSomethingCommand( theForm.Name ) );
return RedirectToAction( "ShowSomething", new {Id = ???} ) // ***** where to get the id from? ***
}
public ActionResult ShowSomething( SomeUrl url )
{
var somethingView = _views.Load<SomeUrl,ShowSomethingView>( url );
if( view == null )
{
return View( "SomethingNotFound" );
}
return View( somethingView );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment