Entity Framework + Life Time + StructureMap + Unit of Work + Windows Forms?

I have a Windows service (or Windows Forms) , and after the timer expires, my service performs some tasks.

I do not want to use only one Entity Framework context while my application is running.

I saw a factory session in NHibernate . Is there something similar for EF ?

This is how I use EF + StructureMap in my ASP.NET or MVC applications :

Application start:

ObjectFactory.Configure(Function(config) config.For(Of IUnitOfWork).HybridHttpOrThreadLocalScoped.Use(Of UnitOfWork)())

End Request:

ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects()

My UnitOfWork is running on a web request and located after the request is complete.

Win App UoW , .

- Windows Form?

UoW, : HybridHttprThreadLocalScoped UoW , , .

EDIT:

+ dll, -, win-, - HybridHttpOrThreadLocalScoped.

2:

:

Public Class ProductRepository

    Private ReadOnly _databaseFactory As DataAccess.IDatabaseFactory

    Public Sub New(ByVal databaseFactory As DataAccess.IDatabaseFactory)
        _databaseFactory = databaseFactory
    End Sub

    Public Function GetById(ByVal id As Integer) As Product
        Return (From item In _databaseFactory.GetDataContext.Products Where item.ProductId = id).FirstOrDefault
    End Function

End Class

:

Public Class ProductService

    Private ReadOnly _Repository As ProductRepository

    Public Sub New(ByVal repository As ProductRepository)
        _Repository = repository
    End Sub

    Public Function GetById(ByVal id As Integer) As Product
        Return _Repository.GetById(id)
    End Function

End Class

StructureMap. StructureMap DatabaseFactory UoW web. , win apps. UoW , , StructureMap , -.

+3
3

ASP.Net ( , httpcontext ) . winforms () . , EF .

, MVP MVVM, ViewModel. " " . .

Ayende ( NHibernate, . Think NHibernate Session = = Entity Framework ObjectContext)

+4

- , . . , (, ..), . .

( ).

UPDATE:

+1

Entity Framework "", , , , . Entity Framework Unit Of Work. EF , , .

, , SaveChanges.

- ASP.NET, , , .

Entity Framework, .

, ? . , . .

, , , .

+1

All Articles