I wonder If I could implement Observable design pattern in ASP.Net MVC 3.
I want that every time an information like a value existing on the server, the browser should be notified when there is a change.
Can I do this? If yes, how? Please post examples or link to such examples.
There's a few things you should take a look at before you start building your own.
First, SignalR
http://www.hanselman.com/blog/AsynchronousScalableWebApplicationsWithRealtimePersistentLongrunningConnectionsWithSignalR.aspx
Second, read this article that was just recently posted about the Trello web stack. They talk about how they implemented client side updating.
http://blog.fogcreek.com/the-trello-tech-stack/
(The pushing and pulling section)
http://en.wikipedia.org/wiki/Long_polling#Long_polling
http://en.wikipedia.org/wiki/Web_worker
Or as simple method use javascript for pinging server time to time to ask if new data exists, and load it when it occured.
Related
I would like to improve my knowledge, because I notice several time, I am convince I develop without to use the right practices, exemple to export a csv in ASP.NET MVC, I create in the controler 4 private methods, these methods do the necessary and return data.
I combine in 1 method, the 4 methods and call the parent method when the use click on export CSV.
These 4 methods are used in two places differents. So I can factorize the code in one for each or maybe it's possible to use delegate. Sure.
So I follow the tutorial from
http://msdn.microsoft.com/en-us/library/aa645739(v=vs.71).aspx about the event
and
http://msdn.microsoft.com/en-us/library/aa288459(v=vs.71).aspx about the delegate
And now, I think, it's not possible to create a listener to manager event in Web context.
My assumption is Web is not connected env, so you lost context each time.
Do you know a technical way to manage event+listener with webContext?
If you have any documentation/link about a pattern to implement it will be a plleasure to read.
You can make your API (Controller action/ WEB API) ‘context/session aware’ by using a session Id to refer to the same session. This way your server side logic will be able to ‘remember’ things for you, thus emulating a concept of a context.
This approach falls out of favour when you look at it from scalabilities’ point of view where your request would be served by one of many servers in a server cluster (unless you implement a dedicated session sharing mechanisms).
Best would be to implement a business service layer which would encapsulate all you atomic and repetitive logic and get the controller actions / web apis to call the service methods
hope this helps
I'm a .Net desktop applications developer trying to switch to ASP.Net MVC (3 or 4 doesn't matter). We have a .Net library which notifies any GUI you want to put on this assembly by Property Changed Events (or any other custom event we deemed necessary for that matter).
This might not even be a relevant question, because perhaps it's done totally different in ASP.Net MVC, but how do you update your View in the browser on your client after receiving a Property Changed Event from an assembly on your server? We generate these events ourselves by the way. The assemblies are our own.
I've read about Partial Views, but I need to look into that. Whatever I came across seemed so cumbersome. Because it's really straight forward and simple in desktop development. So I'm starting to wonder if Property Changed Events are the way to go when developing for the web.
Thoughts? Links? Sources? I'm interested.
p.s.: See tags for a further understanding of what I'm going for.
HTTP world is entirely different
you request something from the server(Asp.Net MVC) and you get a response back from the server.
there is no way in which the server can contact the user back** as the asp.net server wouldnt keep anything in memory after the response
so here you are wrong in 2 aspects
1. property changes - because after the response there is nothing in the memory of the server there are no models(Objects) so there is nothing whoz property is actually changing
2. even if u maintaining something static if that changes there is no way for you to contact the client back
**there are some frameworks available that allow you to contact the client back and they do this by sockets or comet
You need to move away from the Event-driven thinking of desktop (and WebForms for that matter)-development.
MVC is a designpattern for separation of concerns, and no tightly bound events will exist, unless you do some hack-ish work of your own.
You can, however, accomplish this by using frameworks like SignalR that rely on Javascript and open connections, but the notion of events is not present in MVC.
I'd like to use WebAPI as my API technology to:
Allow approved companies to enter/retrieve data in my systtem
Create a standard interface for my company's iOS/Android/etc. applications
Does anyone know of best practices for, and mechanisms used to implement, versioning of interfaces. Specifically, I don't want to break backwards compatibility if I make updates to my API. I'd like to know what versioning schemes people use and if WebAPI has any built in mechanisms supporting versioning without the need to set up routes/paths every time a new version is released. Any thoughts would be appreciated.
Update
After performing some research I think I know what I want to do, I'm not sure how to do it. Ideally during content negotiation I would like to use a media type passed by the user to specify which version of the API should be used (rather than hard-coding the URL) and hit the corresponding controller.
If you don't want the version to be included in the Url, the way to go is probably to implement IHttpControllerSelector. This blog post should give you a good starting point: Implementing API versioning in ASP.NET Web API
I recommend you take a look at Peter Williams' series of blog posts on versioning REST services. They explain the what and why. For the how, check out Mike Wasson's tutorial on how to create a custom media formatter.
How to fetch all data required for processing a request in one call to DB. Also I want to know how will I do this if my master page also requires some data from database? I know that its clarified in Passing data to Master Page in ASP.NET MVC. But I think that will make multiple calls to database. Please let me know if it's not like that.
UPDATE
+1 and thanks to all answerers/commenter s for their views and advice.
I think you might be confusing one session per request and SELECT N + 1 scenarios. It is perfectly fine to have multiple calls to the database, however you want to watch out for when you have to do one database call per item in a list. This is most commonly encountered when using lazy loaded lists. The solution is to use eager fetching.
ps. I think the popular solution for getting data to the master page is to use Html.RenderAction in the master page. That way you don't have to worry about master page concerns (like navigation) all over the place.
I have to agree with the other answers, what is your justification for this?
NHibernate can batch SQL statements using FUTURES, have you read this blog post?
However said I am not sure how you would combine all possibilities for all of your views on your site. If you do come up a solution I would love to see it.
This is not going to be easy and showing a small code example is not possible.
It's a bit of a tall order to limit yourself to only one database hit per request. What are your reasons for doing this? Is it just a fun challenge you've set yourself? If it's for optimisation reasons, there are better ways of achieving this: optimising queries, caching etc.
I am building a Silverlight 3.0 app based on the Silverlight Navigation Application template. One road block I ran into is communicating between the Pages. For instance, I am in one Page, and I want to kick off another page and send it some data. I am at a loss as to how to do this.
Any ideas?
You have 2 options
Use Publish/Subscribe pattern, i havent used this before, but it is useful in certain cases, i dont think it would solve ur problem though.
Use Request parameters, basically when you navigate to the new view, call it like so
NavigationService.Navigate(new Uri("/HomePage.xaml?HomePageId=12", UriKind.Relative));
You could slap some string.format in there to make it neater, but you get the idea, then on the new View, use string queryParam = HtmlPage.Document.QueryString["HomePageId"]; on page load to get the Id of the information you wish to display.
That should do it.
I've found an effective solution that does not involve too much complexity. I am using the LocalMessageSender and LocalMessageReceiver objects. The original purpose of these objects are to have 2 silverlight apps on the same web page talk to each, but it's just as good at having 2 views talk to each other.
The usage is really straight-forward. See this example for usage.
Jesse Liberty has an excellent blog post about just this. I use the techniques described there myself in a multi page Silverlight application.
I'm not sure though whether you can apply this with the Silverlight Navigation Application template.