none
Arranging ASP.NET MVC application into separate module RRS feed

  • Question

  • I have an asp.net mvc 2 application. It is a very big application having different modules. I want to separate each modules functionality wise.  I have tried using class libraries out side the mvc project and inside the solution referencing the mvc project dll and also able to write classes by calling model class of mvc. But when this class library I want to call in controller class inside mvc it is saying that circular dependency. So it is impossible to add class lib reference back to mvc dll. I have no idea how to arrange this. Help me. 
    Saturday, July 27, 2013 12:17 PM

Answers

  • It should be very siomple to create a new module provided you add the namespace properly and you divided the code properly.  YOu should create instances of each class and pass the instance from one class to another if you are calling between classes.  Can you simplify your code by just posting the functions with only the code that reference the calls to the clases so I can see what you are actualy doing?  Include the call statement you are making and any instances of the classes you are using.

    jdweng

    Saturday, July 27, 2013 4:57 PM
  • By the way, the question involved does not only applies to ASP.NET, it applies to WinForm as well so I think it's appropiate to ask here.

    Some tips for seperating libraries with the problem you mentioned.

    First, the dirty way. Maybe in the classes that you want to call the controller class you can create a public property accepting interface of the controller class (The interface should be declared in a seperate class library project that is referenced by both projects), and when the controller want to call the library function, it passes "this" into that property, so when the class libraries want to access the exposed functionalities of the controller, it can access them. (Reminder, the class libraries never should call the Action of controller. Just call the codes the Action refers to directly)

    Or in the Right way, you should define structures/classes for parameter passing and delegate signatures, can then properly assign them as parameters of the function calls.

    Monday, July 29, 2013 2:43 AM
    Answerer

All replies

  • It should be very siomple to create a new module provided you add the namespace properly and you divided the code properly.  YOu should create instances of each class and pass the instance from one class to another if you are calling between classes.  Can you simplify your code by just posting the functions with only the code that reference the calls to the clases so I can see what you are actualy doing?  Include the call statement you are making and any instances of the classes you are using.

    jdweng

    Saturday, July 27, 2013 4:57 PM
  • Hi,

    Welcome to the MSDN forum!

    You'll need to post it in the dedicated ASP.Net Forum http://forums.asp.net for more efficient responses, where you can contact ASP.NET experts.Thank you for your cooperation.

    Thanks for Joel's post at the same time.

    Have a nice day!
    Damon


    Damon Bu - MSFT
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, July 29, 2013 2:22 AM
  • By the way, the question involved does not only applies to ASP.NET, it applies to WinForm as well so I think it's appropiate to ask here.

    Some tips for seperating libraries with the problem you mentioned.

    First, the dirty way. Maybe in the classes that you want to call the controller class you can create a public property accepting interface of the controller class (The interface should be declared in a seperate class library project that is referenced by both projects), and when the controller want to call the library function, it passes "this" into that property, so when the class libraries want to access the exposed functionalities of the controller, it can access them. (Reminder, the class libraries never should call the Action of controller. Just call the codes the Action refers to directly)

    Or in the Right way, you should define structures/classes for parameter passing and delegate signatures, can then properly assign them as parameters of the function calls.

    Monday, July 29, 2013 2:43 AM
    Answerer