Created
February 3, 2011 02:56
-
-
Save jmarnold/808960 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public void Invoke() | |
{ | |
if (performInvoke() == DoNext.Continue && InsideBehavior != null) | |
{ | |
InsideBehavior.Invoke(); | |
} | |
afterInsideBehavior(); | |
} | |
protected virtual DoNext performInvoke() | |
{ | |
return DoNext.Continue; | |
} | |
protected virtual void afterInsideBehavior() | |
{ | |
} |
This file contains hidden or 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
public class CreateEntityAction<TEntity, TInput> | |
{ | |
private readonly IUnitOfWork _unitOfWork; | |
private readonly IMappingRegistry _mappingRegistry; | |
public CreateEntityAction(IUnitOfWork unitOfWork, IMappingRegistry mappingRegistry) | |
{ | |
_unitOfWork = unitOfWork; | |
_mappingRegistry = mappingRegistry; | |
} | |
public void Execute(TInput input) | |
{ | |
var entity = _mappingRegistry.Map<TInput, TEntity>(input); | |
_unitOfWork.Initialize(); | |
_unitOfWork.Insert(entity); | |
_unitOfWork.Commit(); | |
} | |
} |
This file contains hidden or 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
public interface IActionBehavior | |
{ | |
void Invoke(); | |
void InvokePartial(); | |
} |
This file contains hidden or 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
public class ProjectsController | |
{ | |
// dependencies... | |
[AcceptVerbs(HttpVerbs.Post)] | |
public ActionResult Create(CreateProjectInput inputModel) | |
{ | |
var result = _createEntityService.Create<Project>(inputModel); | |
if(!result.Success) | |
{ | |
result.Errors.Each(_errorService.Register); | |
return Create(); | |
} | |
return View("Details", new { ProjectId = result.Project.ProjectId }); | |
} | |
} |
This file contains hidden or 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
public void Invoke() | |
{ | |
try | |
{ | |
InsideBehavior.Invoke(); | |
} | |
catch(Exception exc) | |
{ | |
// we'd probably want better error reporting... | |
_errorService.RegisterError(exc); | |
// redirect | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment