What I did is to register the iuserservices as property injection instead of 
using constructor injection with that I can have access to different iservices 
in d controller.
Sent from my BlackBerry® smartphone provided by Airtel Nigeria.

-----Original Message-----
From: Gitted <[email protected]>
Sender: [email protected]
Date: Sat, 17 Sep 2011 10:31:57 
To: Castle Project Users<[email protected]>
Reply-To: [email protected]
Subject: Advice on how to setup controllers and "service" layer

In my asp.net mvc3 application, I will need access to my service layer
(nhibernate service classes that wrap my repositories).

And also, from within my nhibernate service layer, I will need access
to other services from within a given service, but for some reason
most examples seem to show that the UserService only needs
UserRepository.

e.g.

UserService will need access to the UserRepository, but also a
particular method might need access to another service, how should I
wire this up?  Should I inject all services or just the ones I need?

public class UserService : IUserService
{
   private IUserRepository _userRepositry;

   public UserService(IUserRepository userRepository)
   {
        this._userRepository = userRepository;
   }


   public void SomeMethod()
   {

       // need access to IContentRepository

   }
}

I guess the obvious thing is to add IContentRepository to my
constructor, and just continue with this kind of pattern i.e. add
whatever repository I need in the constructor on a need basis right?

BTW, will I have to register each dependancy individually or do I just
do it once and the container will figure it out?

This same issue arises in my MVC Controllers i.e. some controllers
might only need access to a single service like IUserService, while
others will need access to multiple services.

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to