Search Results

Search found 2 results on 1 pages for 'e36m3'.

Page 1/1 | 1 

  • Ninject InThreadScope Binding

    - by e36M3
    I have a Windows service that contains a file watcher that raises events when a file arrives. When an event is raised I will be using Ninject to create business layer objects that inside of them have a reference to an Entity Framework context which is also injected via Ninject. In my web applications I always used InRequestScope for the context, that way within one request all business layer objects work with the same Entity Framework context. In my current Windows service scenario, would it be sufficient to switch the Entity Framework context binding to a InThreadScope binding? In theory when an event handler in the service triggers it's executed under some thread, then if another file arrives simultaneously it will be executing under a different thread. Therefore both events will not be sharing an Entity Framework context, in essence just like two different http requests on the web. One thing that bothers me is the destruction of these thread scoped objects, when you look at the Ninject wiki: .InThreadScope() - One instance of the type will be created per thread. .InRequestScope() - One instance of the type will be created per web request, and will be destroyed when the request ends. Based on this I understand that InRequestScope objects will be destroyed (garbage collected?) when (or at some point after) the request ends. This says nothing however on how InThreadScope objects are destroyed. To get back to my example, when the file watcher event handler method is completed, the thread goes away (back to the thread pool?) what happens to the InThreadScope-d objects that were injected? EDIT: One thing is clear now, that when using InThreadScope() it will not destroy your object when the handler for the filewatcher exits. I was able to reproduce this by dropping many files in the folder and eventually I got the same thread id which resulted in the same exact Entity Framework context as before, so it's definitely not sufficient for my applications. In this case a file that came in 5 minutes later could be using a stale context that was assigned to the same thread before.

    Read the article

  • Nhibernate: one-to-many, based on multiple keys?

    - by e36M3
    Lets assume I have two tables Table tA ID ID2 SomeColumns Table tB ID ID2 SomeOtherColumns I am looking to create a Object let's call it ObjectA (based on tA), that will have a one-to-many relationship to ObjectB (based on tB). In my example however, I need to use the combination of ID and ID2 as the foreign key. If I was writing SQL it would look like this: select tB.* from tA, tB where tA.ID = tB.ID and tA.ID2 = tB.ID2; I know that for each ID/ID2 combination in tA I should have many rows in tB, therefor I know it's a one-to-many combination. Clearly the below set is not sufficient for such mapping as it only takes one key into account. <set name="A2" table="A2" generic="true" inverse="true" > <key column="ID" /> <one-to-many class="A2" /> </set> Thanks!

    Read the article

1