Membrane - CRUD Service

John | .Net, Membrane, MonoRail | Sunday, April 12th, 2009

So we’ve talked about Membrane’s CRUDController, and as stated most of the time developers won’t need to do anything more than inherit from the CRUDController when writing new plugins. There will be occasions where developers need to overwrite the functionality of the CRUDService though.

What the CRUDService currently does

As stated in my previous post about the CRUDController the plan is to make everything as easy as possible to set up. The CRUDService currently runs off the following interface.

public interface ICRUDService<TDto, TEntity>
{
	void RegisterMappings();
	IList<TDto> GetPagedItems(int currentPage, int pageSize);
	IList<TDto> GetItems();
	TDto GetItem(Guid id);
	Guid Create(TDto group);
	bool Update(TDto group);
	bool Delete(Guid id);	
}

The RegisterMappings method maps the DTO to the Entity and vice-versa using Jimmy Bogard’s AutoMapper.

public virtual void RegisterMappings()
{
	Mapper.CreateMap<TEntity, TDto>();
	Mapper.CreateMap<TDto, TEntity>();
}

These mapping are very basic, but in most cases this should do the trick. For anymore complex mappings the developer will need to create a new service inheriting from the CRUDService and overwriting the RegisterMappings method.

Injecting a new service

When a developer needs to have differing functionality to that provided by the CRUDService, they can either create a new service inheriting from the CRUDService and overwrite the methods that need changing, or they can write a completely new service. If they write a new service they will need to override the CRUDController work to make the appropriate calls to the service.

This new service will need injecting into the controller. This will mean registering the service with the Castle Windsor container. Fortunately we have an easy way of doing this as well. I’ll blog about this another time.

Unit Tests

If inheriting from the CRUDService the developer will be able to run their service against a CRUDServiceFixture, thus making testing very quick and easy. Again, just like the CRUDControllerFixture, all tests are override-able.

Flexible enough?

If you have experience with other CMS systems, does the CRUDController and CRUDService sound flexible enough for you? Could it be made simpler whilst maintaining a certain standard of coding?

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress | Theme by Roy Tanck