For more info visit wiki: (https://github.com/lcranf/MyMvcSample/wiki)
MyMvcSample is intended as a blueprint for using ASP.NET MVC3 with an Ioc (in this case Ninject) with EF Code First and MvcScaffolding. The project will eventually include several T4Scaffolding templates which will auto generate files for CRUD'ing operations. This project also makes use of Ninject Conventions (http://bit.ly/reik9G) to allow services to be auto-discovered that reside in assemblies within the App Domain. The overall design starts with service classes which are responsible for the nuances surrounding CRUD'ing an Entity. An example service interface and corresponding class is below for an Order entity:
public interface IOrderService : ICrudService<Order>
{
//add custom methods for Order here...
}
public class OrderService : CrudService<Order>, IOrderService
{
public OrderService(IRepository<Order> repository)
: base(repository)
{
}
}
Note: The above classes will be auto generated by the supplied T4Scaffolding templates. To scaffold up the service and cooresponding controllers and views run the following in the Powershell command window in Visual Studio:
Scaffold ControllerWithService Order -NoIoc
Note: The -NoIoc switch will force the scaffolder to generate default contructors for the Services and Controllers
Be aware that in this architecture all entities must inherit from IEnity
. The sample also using the EF Hooks project (http://bit.ly/p9XJ4E) to manage standard audit fields (CreatedOn, CreatedBy, etc...) automatically
Controller Layer
A controller will be scaffolded with a reference to it's corresponding Service class. This helps keep the controller Thin and free of any clutter not related to it's navigational responsibilities. A base example of a scaffolded controller is below:
public class OrderController : BaseController
{
private readonly IOrderService _orderService;
public OrderController(IOrderService orderService)
{
_orderService = orderService;
}
}
Note: Since all services are auto-registered with Ninject Conventions, there is no need to worry about mucking around with an Ioc configuration file. All services will be registered and properly resolved at runtime.
For more info visit wiki: (https://github.com/lcranf/MyMvcSample/wiki)
TODO's
- Add Elmah and ElmahErrorHandler to project
- Implement ElmahController to bypass using the default Elmah Http Handler
- Add T4MVC to eliminate strings
- Add MVCContrib for test helpers and stuff...