You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This gist highlights a more complex example on how to implement autofac delegating factories to create container driven dependencies with runtime paramaters.
Please see this article for a primer before delving into the code here:
Here are a few different ways to try and implement prototypal inheritance in a classical way.
In these examples, we try to derive a more specific class of the base class - Asset.
By inspecting the web development tools console output in Chrome you can see the prototype chain and view the differences of each approach.
Making web.config appSettings available via JavaScript (ASP.NET MVC)
Making web.config appSettings available via JavaScript (ASP.NET MVC)
You may wish to expose server side configuration via JavaScript. For example, you may have a different base url for your REST api per environment (dev,test,uat,prod) which your JavaScript AJAX calls need to consider.
Typically, you would push the configuration data down via an html5 data- attribute, a hidden input field or via explicit assignment to a JavaScript global. You usually end up doing this for every item you wish to expose. However, using a custom MVC ActionFilterAttribute and a Server-to-JSON serialization technique you can easily expose your web.config appSettings for controller actions.
NOTE: Exposing the entire appSettings configuration section may expose your application to security risks.
Transferring Server data to JavaScript with initial Page Request
Transferring Server data to JavaScript with initial Page Request
Often you want to return data with your call to retrieve a web page/control from ASP.NET MVC so that it can be accessed via JavaScript as a ViewModel (using KnockoutJS or equivalent).
Typically, you make a server call to retrieve the web page using the standard ASP.NET controller action and then make a AJAX call to go retrieve the model to populate your JavaScript ViewModel.
Wouldn't it be nice if you could send back the model with the page request and avoid a separate AJAX call?