I have a Customer controller which has it's CustomerRepository injected in.
For my Create new Customer view I am going to be editing/adding an address and assigning to the customer, but an Address entity has a Country property which is a link to a simple Country entity.
I want to populate a dropdownlist with the list of available Countries for my Create Customer view. How would you acquire the data for your Countries collection from within a Customer controller? Creating a new CountriesRepository inside a customer controller
which has had it's repository injected into it doesn't feel right? Am I missing a trick?
You would add a CountriesRepository to what is injected in the controller. If you do not need the CountriesRepository for all the methods, just the add/edit one, you could use Method Injection instead of Constructor Injection.
I faced a similar question when i tried to select a category from a drop down list box in a create new blog entry view. I managed to add a simple property in the blog entity (in your case "customer") something like so:
public ICollection<Country> Countries { get; set; }
then you should be able to bind this to a drop down list box for you create view
Moorzee
Member
4 Points
11 Posts
Injected repository and other repository access question
Oct 02, 2012 10:23 AM|LINK
I have a Customer controller which has it's CustomerRepository injected in.
For my Create new Customer view I am going to be editing/adding an address and assigning to the customer, but an Address entity has a Country property which is a link to a simple Country entity.
I want to populate a dropdownlist with the list of available Countries for my Create Customer view. How would you acquire the data for your Countries collection from within a Customer controller? Creating a new CountriesRepository inside a customer controller which has had it's repository injected into it doesn't feel right? Am I missing a trick?
Thanks for help.
DarrellNorto...
All-Star
86555 Points
9624 Posts
Moderator
MVP
Re: Injected repository and other repository access question
Oct 02, 2012 10:30 AM|LINK
You would add a CountriesRepository to what is injected in the controller. If you do not need the CountriesRepository for all the methods, just the add/edit one, you could use Method Injection instead of Constructor Injection.
Ninject does it, see here: http://ninject.codeplex.com/wikipage?title=Injection%20Patterns
Most DI containers do it. Look up the "how to" for your particular one.
Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
bweber89
Member
486 Points
119 Posts
Re: Injected repository and other repository access question
Oct 02, 2012 10:32 AM|LINK
Hi Moorzee
I faced a similar question when i tried to select a category from a drop down list box in a create new blog entry view. I managed to add a simple property in the blog entity (in your case "customer") something like so:
public ICollection<Country> Countries { get; set; }then you should be able to bind this to a drop down list box for you create view
hope that this helped in any way
Junior Software Developer