What is the proper way to access datastore in custom Model Binders?
Posted
by mare
on Stack Overflow
See other posts from Stack Overflow
or by mare
Published on 2010-04-11T20:09:12Z
Indexed on
2010/04/11
20:13 UTC
Read the original article
Hit count: 262
How should I properly implement data access in my custom model binders?
Like in controllers I use IContentRepository and then have it create an instance of its implementing class in constructor. So I have everything ready for incorporating IoC (DI) at a later stage.
Now I need something similar in model binder. I need to make some DB lookups in the binder. I'm thinking of doing it the same way I do it in controllers but I am open to suggestion.
This is a snippet from one of my controllers so you can imagine how I'm doing it in them:
public class WidgetZoneController : BaseController
{
// BaseController has IContentRepository ContentRepository field
public WidgetZoneController() : this(new XmlWidgetZoneRepository())
{
}
public WidgetZoneController(IContentRepository repository)
{
ContentRepository = repository;
}
...
© Stack Overflow or respective owner