danfromisrael (4) [Avatar] Offline
#1
(I posted my original question in stackoverflow, trying it here as well)

In my logic classes i have ajax calls to web services, i store stuff in cookies, get info from the uri query string and display messages to the user.

What would be a best practice to decouple my logic class from those dependencies?

My environment: I'm developing with SharpKit ( C# to javascript compiler ) so i'm writing in c# and eventually my code compiles into pure javascript and runs only on the browser (no server side code).

At the begining i was thinking of wrapping them as a 2 repositories: 1 for ajax calls and the others for browser all interaction(cookies, urls, messages, etc..)

right now it looks something like that (without DI):

public class CustomersScreenController
{

public CustomersScreenController(Services services, CookieHelper cookieHelper, UriHelper uriHelper)
{ ... }

}

Does it make sense i'd put all browser's stuff in one repo? On the other hand, Cookies and Query Strings seems to me like another data source...

What do you think ?


=======================
Stackoverflow question:

http://stackoverflow.com/questions/19895453/dependency-injection-whats-the-best-way-to-decouple-my-logic-class-from-depend
danfromisrael (4) [Avatar] Offline
#2
Re: Whats the best way to decouple my logic class from dependencies in web ?
another question:

How would you layer this kinda app ?

ajax calls seems to be the Data Layer
controllers are the Logic Layer
and BrowserStuff (cookies, url, messages) the UI Layer?

Currently it works with MVC like this:
Controller makes the ajax calls and fills the Model with data,
Model is one way databinded to the View that has all the display objects(text boxes, grids, etc..)
View takes care of view logic like rendering, hovering, clicks etc.. and fires events into the controller.

eventually i'd love to test the controllers so i want to start using DI
mark.seemann (383) [Avatar] Offline
#3
Re: Whats the best way to decouple my logic class from dependencies in web ?
Hi

Thank you for writing. I left some comments on your SO post.

Regards

Mark Seemann