tag:blogger.com,1999:blog-15136575.post8147429509601550369..comments2023-10-17T12:00:16.772+01:00Comments on Code rant: The MVC 3.0 IDependencyResolver interface is broken. Don’t use it with Windsor.Mike Hadlowhttp://www.blogger.com/profile/16441901713967254504noreply@blogger.comBlogger13125tag:blogger.com,1999:blog-15136575.post-63986747446473740392011-08-29T21:50:59.530+01:002011-08-29T21:50:59.530+01:00end of tenancy cleaning You are a smoker? Well the...<a href="http://end-of-tenancy-cleaning-london.co.uk" rel="nofollow">end of tenancy cleaning</a> You are a smoker? Well then you do not mind the tobacco smell in your apartment, but what if you expect guest who do not smoke at all? Smoking is really endangering your heath no matter if you are a real or passive smoker. The smoke is also very unhealthy for small children and pets, because they inhale of those bad smoke compounds that the cigarette contain. Statistics shows that people who inhale all the bad elements are not the smokers, but the passive one’s. You need to be very careful. <a href="http://end-of-tenancy-cleaning-london.co.uk" rel="nofollow">post tenancy cleaning</a>Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-57251468272349474832011-03-24T19:35:01.275+00:002011-03-24T19:35:01.275+00:00Sorry accidently posted not completed post early.
...Sorry accidently posted not completed post early.<br />PS: I do not remember where we got this code from. It basically redefines Trasient LifeStype Policy so IoC does not keep track of it internally. TrulyTransientLifestyleManager can be leaft out from method above. Unless you want to define it ans do some custom things with it.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-37370565564042161372011-03-24T19:26:48.684+00:002011-03-24T19:26:48.684+00:00We do not use dependency resolver yet in our MVC p...We do not use dependency resolver yet in our MVC project, but Windsor is used for other parts of the project. Here is how we compensate for lack of Release method in similar cases.<br />Define lifetime policy:<br /><br />[Serializable]<br /> public class TrulyTransientReleasePolicy : LifecycledComponentsReleasePolicy<br /> {<br /> public override void Track(object instance, Burden burden)<br /> {<br /> ComponentModel model = burden.Model;<br /><br /> if (model.LifestyleType == LifestyleType.Transient)<br /> return;<br /><br /> // we skip the tracking for object marked with our custom Transient lifestyle manager<br /> if ((model.LifestyleType == LifestyleType.Custom) &&<br /> (typeof(TrulyTransientLifestyleManager) == model.CustomLifestyle))<br /> return;<br /><br /> base.Track(instance, burden);<br /> }<br /> }<br /><br />And then simply assign:<br /> ioc.Kernel.ReleasePolicy = new TrulyTransientReleasePolicy();Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-39850758154599715122011-02-04T14:18:29.415+00:002011-02-04T14:18:29.415+00:00I had some similar comments about IControllerActiv...I had some similar comments about IControllerActivator.<br /><br />http://bradwilson.typepad.com/blog/2010/10/service-location-pt10-controller-activator.html<br /><br />See near the bottom of the comments.hwiechershttps://www.blogger.com/profile/11242164300585745124noreply@blogger.comtag:blogger.com,1999:blog-15136575.post-3385384026309805432011-02-04T00:45:48.947+00:002011-02-04T00:45:48.947+00:00It's not like they didn't know about it in...It's not like they didn't know about it in advance... http://bradwilson.typepad.com/blog/2010/07/service-location-pt1-introduction.html (see comment trail)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-60166364881291894142011-02-03T22:29:37.205+00:002011-02-03T22:29:37.205+00:00Hi Fschwiet,
Yes, as I said above there are worka...Hi Fschwiet,<br /><br />Yes, as I said above there are workarounds, but it's irritating that we need workarounds when the whole point of the new MVC features was to enable better IoC integration. Apparently the MVC team were told about the problem, but did nothing to fix it. I assume it was because they would have to make their own internal service locator more sophisticated in order to deal with the changed semantics? But then don't make a song and dance about MVC being container friendly when it's not.<br /><br />As you point out, the whole point of having a container is that it is responsible for the component life-cycle. Simply calling Dispose on a component violates that basic principle.<br /><br />Hi Anonymous,<br /><br />My controller doesn't implement IDisposable, that's part of the point :)<br /><br />Hi Jeff,<br /><br />The container needs some signal that it's time to dispose CustomerRepository 'as it normally would', but without the Release call it never gets it.<br /><br />Hi Andy,<br /><br />I do mostly configure my components as Transient in web applications. However, if a component, or any of its dependency chain implements IDisposable, Windsor will keep a handle on it and the GC won't collect it. Krzysztof's post that I referenced explains this point very well. It's a Windsor 101 point: if you resolve a component, you must release it as well.Mike Hadlowhttps://www.blogger.com/profile/16441901713967254504noreply@blogger.comtag:blogger.com,1999:blog-15136575.post-21691643813186904762011-02-03T20:50:23.845+00:002011-02-03T20:50:23.845+00:00Can't you configure your services as ephemeral...Can't you configure your services as ephemeral and get a new instance per instantiation? Then GC will catch-up with unreferenced objects are normal?<br /><br />Or if your services are stateless, configure then as a singleton and re-use the same instance everywhere?<br /><br />(Don't use Windsor myself, but most containers seem to have some sort of configuration along these lines)<br /><br />Am I missing something important here?<br /><br />The only gotcha I can see is if you are performing work in Dispose(), e.g. a commit on a database. Dangerous territory!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-50819693396788321972011-02-03T20:15:44.093+00:002011-02-03T20:15:44.093+00:00What I don't understand is if your container i...What I don't understand is if your container is instantiating CustomerRepository and injecting it into the HomeController, the container should be disposing of your CustomerRepository just as it normally would... despite the IDependencyResolver stuff... right?Jeff Schumacherhttps://www.blogger.com/profile/17853880495304904360noreply@blogger.comtag:blogger.com,1999:blog-15136575.post-31185358528006308062011-02-03T19:26:14.367+00:002011-02-03T19:26:14.367+00:00Mike,
What is your controller doing that it needs...Mike,<br /><br />What is your controller doing that it needs to implement IDisposable?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-32745419282219134892011-02-03T17:47:27.612+00:002011-02-03T17:47:27.612+00:00Interesting point. Doesn't CommonServiceLocat...Interesting point. Doesn't CommonServiceLocator have this problem too though? Krzysztof's post on lifetime was an eye opener for me, so I can't get angry at the MVC team for missing this.<br /><br />If using per-webrequest lifetime for anything that MVC loads is sufficient, I think I'd be fine with that as a work-around for now. But I'd like a windsor expert to confirm that is generally sufficient.<br /><br />I think there might be other problems... For instance, what happens if you register a controller class with singleton lifetime, and that controller implements IDisposeable? It seems like MVC3's auto-dispose logic would not honor the intended lifetime there either.fschwietnoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-72029408766857134982011-02-03T16:48:50.310+00:002011-02-03T16:48:50.310+00:00Hi Adraan, Ken,
Sure there are workarounds for t...Hi Adraan, Ken, <br /><br />Sure there are workarounds for this problem. As you guys say, you could register all your components as PerWebRequest, create some funky controller decorator, or another suggestion is to use a per-web-request child container.<br /><br />But this is silly. Why should we have to think up creative workarounds for a feature of MVC3 that's supposed to enable container use simply because the MVC team couldn't provide a simple release mechanism.<br /><br />My short term plan is to simply stick with the controller factory. My long term plan is look long and hard at open source web frameworks. The MVC team just doesn't seem to get it.Mike Hadlowhttps://www.blogger.com/profile/16441901713967254504noreply@blogger.comtag:blogger.com,1999:blog-15136575.post-42972969109509710412011-02-03T16:27:19.175+00:002011-02-03T16:27:19.175+00:00Maybe you can set up Windsor to return a Proxy to ...Maybe you can set up Windsor to return a Proxy to the controller, which also implements IDisposable, and delegates the Dispose call to container.Release. I have very little time today so I won't be able to actually create the code for this, but I bet that if you take it to the user-group, the good people there (probably Krzsistof) will come up with this in no timeKen Egozihttp://kenegozi.com/blognoreply@blogger.comtag:blogger.com,1999:blog-15136575.post-30186378302331642962011-02-03T14:56:38.722+00:002011-02-03T14:56:38.722+00:00Mike
You could use the PerWebRequest lifecycle in...Mike<br /><br />You could use the PerWebRequest lifecycle in Windsor, that will release all components configured for the this lifecycle.AdriaanPhttps://www.blogger.com/profile/17582542829847087758noreply@blogger.com