Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6537913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:40:23+00:00 2026-05-25T10:40:23+00:00

I am working with a CRM product that uses ASP.net MVC 3.0, Entity Framework

  • 0

I am working with a CRM product that uses ASP.net MVC 3.0, Entity Framework and Windsor for IOC container.

I have injected the services which are work with repository layer to controller through Windsor.

However, I have implemented the strategy pattern for my ContactController to facilitates MyProfile, CustomerProfile, CompanyProfile.

Now my ContactContext class is depended on my ContactController class so that i can’t inject ContactContext using Windsor as a result of that i have created instance of ContactContext in ContactController.

ContactController class implementation

 public class ContactController:BaseController
 {
    private ContactContext _contactContext;

    public ContactController(PersonService personService, CompanyService customerService)
    {
        _contactContext = new ContactContext(personService, customerService, this);
    }

    public ActionResult ContactProfile(string profileId, string profileType)
    {
       base.ValidateContactProfileIdAndProfileTypeInfo(profileType, profileId);
       return _contactContext.RenderContactProfile(ProfileType, ProfileId);
    }
  }

ContactContext implementation

public class ContactContext
{
    private Dictionary<ProfileType, IContactStrategy> _strategies =
    new Dictionary<ProfileType, IContactStrategy>();

    private BaseController _controller;

    public ContactContext(PersonService personService, CompanyService companyService, BaseController controller)
    {
        _strategies.Add(ProfileType.MyProfile, new MyProfileStrategy(personService));
        _strategies.Add(ProfileType.CustomerProfile, new PersonStrategy(personService));
        _strategies.Add(ProfileType.CompanyProfile, new CompanyStrategy(companyService));

        _controller = controller;
    }

    public ActionResult RenderProfileInfo(ProfileType profileType, long profileId)
    {
        return _strategies[profileType].GenerateProfileInfoView(profileId, _controller);
    }

    public ActionResult RenderPeopleInfo(ProfileType profileType, long profileId)
    {
        return _strategies[profileType].GeneratePeopleInfoView(profileId, _controller);
    }
 }

Strategies go like this

public class PersonStrategy:IContactStrategy
{
    private PersonService _personService;

    public PersonStrategy(PersonService personService)
    {
        _personService = personService;
    }


    #region Implementation of IContactStrategy

    public ActionResult GenerateProfileInfoView(long profileId, BaseController controller)
    {
        //TODO: Load Profile info from service
        PersonDetailsViewModel personDetailsViewModel = new PersonDetailsViewModel();
        personDetailsViewModel.Name = "Robert Martin";

        return controller.RenderPartialView("ProfileInfo", personDetailsViewModel);
    }

    public ActionResult GeneratePeopleInfoView(long profileId, BaseController controller)
    {
        //TODO: Load people from service
        return controller.RenderPartialView("PeopleView", new List<PersonLiteViewModel>());
    }
  }

public class CompanyStrategy : IContactStrategy
{
    private CompanyService _companyService;

    public CompanyStrategy(CompanyService companyService)
    {
        _companyService = companyService;
    }

    #region Implementation of IContactStrategy

    public ActionResult GenerateView(long profileId, BaseController controller)
    {
        throw new NotImplementedException();
    }

    public ActionResult GenerateProfileInfoView(long profileId, BaseController controller)
    {
        throw new NotImplementedException();
    }
 }

Question: How can i get rid of ContactContext dependency with ContactController?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:40:24+00:00Added an answer on May 25, 2026 at 10:40 am

    I have implemented factory to create ContactContext and inject it using the container

    public class ContactController:BaseController
    {
     private ContactContext _contactContext;
    
     public ContactController(ContactContextFactory contactContextFactory)
     {
        _contactContext = contactContextFactory.GetContactContext(this);
     }
    }
    
    public class ContactContextFactory
        {
            private PersonService _personService;
            private CompanyService _customerService;
    
            public ContactContextFactory(PersonService personService, CompanyService companyService)
            {
                _personService = personService;
                _customerService = companyService;
            }
    
            public ContactContext GetContactContext(BaseController baseController)
            {
                return new ContactContext(_personService, _customerService, baseController);
            }
        }
    

    Any suggestions or improvements ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using CRM 4, I have an entity form that contains a tab with an
this is a working example of a plugin that I have written for CRM
The shop that I am working part time with is new to Microsoft CRM.
So i've got a CRM that i'm working with and I'm programming a class
I'm working on a solution that has two applications 1) Wordpress based CRM (frontend)
How can I run an ASP.net 4.0 app in the ISV folder on CRM
I have been working on a module to sync data between client side CRM
I'm working on CRM 2011 (newbie...) and created a plugin that checks if incidents
I am new to CRM development. I have a Custom Entity customer. This Entity
I have created an omnibar extension that searches our company crm. I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.