Are spring.net objects created once for each server call? - spring.net

Or are they created once for the whole application?

Depends of the scope :
http://www.springframework.net/docs/1.3.0/reference/html/objects.html#objects-factory-scopes

Related

Is it possible to create a single page application using MongoDB as a backend?

I am trying to use the new single page application project from the upcoming Visual studio and I was wondering if it would be possible to create an application using a MongoDB backend for the DBContext. It seems that the upshot.js library relies heavily on this (for the metadata for inst , for the DBDataController, ...)
Thanks for your help
Unfortunately MongoDB does not have wrappers/support for the entity framework nor the DBContext interface. MongoDB can't be used as the backend for the Entity Framework. See here.
You cant use MongoDB with entity. But for one page application you can use MongoRepository
It's perfect to do something very fast and not to spend time on mongoDb implimantation.

How do you place a web services aside with your ASP.NET MVC web application

I currently have a web application written by ASP.NET MVC. Now I want to add a web service so that some people can easily build application upon it. Shall I just create the asmx in the MVC Web project or create another project referencing to the Model project? And what's the pros and cons?
Thanks in advance!
Easy decision - if your MVC Web project depends on the web service at all, keep it in the MVC Web project. If not, create a separate project for the web service with reference to your model.
Keeping projects seperate allows people to read and understand your code more effectively. If your service makes use of your model, but is not part of that model, than it should definitely be a standalone project with reference to the model. This is clean design.
for my opinion I would do something like this in my solution
solution.Model -- the model that reflects your db,
solution.Repository
solution.MVC -- your model will be the refined Model, referencing the solution.Model
solution.Test
solution.WebService -- referencing solution.Model
I keep my Model outside my MVC Web application and just put the refined ViewModels in my MVC Model folder. I don't know much about pro's and con's but this is just a better way of doing it for me.
Doing this, you can use your Model anyway you want. Maybe you want to use it for WebService as what you ask. Or for another Application. You just reference your Model project to other projects that you need them.
I would look for Odata -> WCF Data Services formaly know as "Astoria".
If you are using for example linq-to-sql or EF you can make your data in a restful manner availale and provide a basic api...
You can define your endpoint like you do in WCF because the underlying service is based on WCF. And I would use a different namespace...
Website
http://msdn.microsoft.com/en-us/data/bb931106.aspx
Beginners guide with videos
http://msdn.microsoft.com/en-us/data/ee720180.aspx
open data format
http://www.odata.org/

Use StructureMap with WCF 4.0 REST Services

How do I use StructureMap in a WCF 4.0 REST service?
I've used StructureMap in the past using this article but the technique doesn't seem to work with the WebServiceHostFactory(). What's the secret?
The method in the previous example article can be made to work by:
deriving StructureMapServiceHost from WebServiceHost and not ServiceHost
deriving StructureMapServiceHostFactory from WebServiceHostFactory and not ServiceHostFactory
The benefit of this? No web.config changes required. It's all done programatically.
In addition to Alex's instruction, you need to wire up your ServiceHostFactory in the service route of your service instead of using WebServiceHostFactory.
RouteTable.Routes.Add(new ServiceRoute("MemberProvisioning/Api", new IoCServiceHostFactory(), typeof(MemberService)));
Hope this helps.
I got it to work following this example. Essentially you write a customer BehaviorExtension instead of a ServiceHostFactory and life is good.
Would still appreciate any understanding as to why using a custom WebServiceHostFactory doesn't work. It appeared to wire everything up correctly but my IInstanceProvider's GetInstance() method was never being called.

Should I use StructureMap or Session to manage a concrete instance?

I am using StructureMap on an ASP.NET MVC project. I have an object that I want to use throughout the session. Should I use StructureMap or Session:["MyObject"] to manage the concrete instance? Thanks in advance.
This will depend on your scenario. If this instance is tied to a particular user and should not be shared between other users you should use Session. For example use Session to store products that the user added to his cart in an e-commerce application.
If it is for injecting dependencies such as repositories into your controllers and managing controllers StructureMap is fine.

Can Dependency Injection delay creating objects required?

I'm playing around with some Dependency Injection (StructureMap) with my ASP.NET MVC application. Works great.
Becuase StructureMap is using DI via the most gready constructor (I hope I got that concept named right), I'm under the impression that it creates an instance of an object for each argument, in the most gready constructor.
So, is it possible to tell a DI framework (in this case, it's StructureMap but i'm curious if it can do it for any other .NET DI Framework) to NOT create the instance when the constructor is called, but to delay that object's construction until required?
Sorta like some lazy-object construction or something...
All di frameworks that support singleton->session/request scoped mappings typically instantiate a proxy object instead of the "real" object when a singleton object needs to access a session scoped object. Construction of the "real" instance is normally deferred to the first time a method on the proxy is invoked.
I believe castle windsor supports this mechanism.
Short answer: Yes, you can do this. Register your types using the .Net 4 Lazy<T> class like this:
x.For(typeof(Lazy<>)).Use(typeof(Lazy<>))
.CtorDependency<bool>("isThreadSafe").Is(true);
For the long answer and explanation, see my answer to question 6811956. I think it will give you what you need. If you aren't using .Net 4 you'll have to implement your own Lazy<T> class to pull this off. See question 3207580 as a starting point.
Does Structuremap support Lazy out of the box?
Implementation of Lazy<T> for .NET 3.5
UPDATE: In StructureMap 3, "CtorDependency" has become just "Ctor", but otherwise seems to be working just the same.

Resources