Where does Inversion of Control exist in Entity Framework? - entity-framework

I've read some articles (Stackoverflow, Wikipedia, Simone Busoli, etc.) about Inversion of Control (IoC) and am starting to get my head around the concept. I've also been studying the Entity Framework (EF) and am wondering where specifically IoC is present within the EF? Here's a simple EF example I've been looking at: (EF Code First: new DB)

Inversion of Control is a pattern that aims at loosely coupling an application. It puts the application in charge of all of its dependencies (whether or not they are in libraries or frameworks).
EF is not an application, it is a library. You can wire it up with IoC, but since it is not an application, it contains no IoC.
That said, it is possible to develop frameworks and libraries to be IoC or DI (dependency injection) friendly. There are a couple of great articles on that topic:
http://blog.ploeh.dk/2014/05/19/di-friendly-library/
http://blog.ploeh.dk/2014/05/19/di-friendly-framework/
Mark Seemann (the author of that blog) has written a great book on the subject of DI in .NET, which I highly recommend because there is a lot of misinformation and outdated information on the web about IoC and DI. I am confident once you read the book you will understand how to use IoC with EF, but it is not something that can be answered in a paragraph or two.

Related

Domain Driven Desing applying in .Net with Entity Framework

I am learning the Domain Driven Design and I saw some concepts the following Aggregate, UnitOfWork,... I am reading the books that including java based applications. But Entity Framework is growing up in .Net framework. Entity Framework is including DbContext, IDbSet,...
Is there a nice sample that applied domain driven design in .Net
Matching the concepts
I personally think that Microsoft Spain has done a great job in providing a learning example. It's not for the "faint-hearted", and it's not the "only way to do it", but you may find it interesting. Have a look at https://microsoftnlayerapp.codeplex.com/ ?

Persistence in .net - ADO.NET Entity Framework

I couldn't found a clear answer on that:
Is the ADO.NET Entity Framework a full featured persistence framework like Hibernate for Java?
Is there a any (other) persistence framework in .net? I only found open source frameworks like nHibernate but no clear answer if there is something build-in in .net. What's the best practice to get persistence in .net?
when you talk about persistence layer, usually that is databases or file systems, when you talk about Entity Framework it is called ORMs, and yes, I think in the .Net environment NHibernate and Entity Framework should be two of the most popular ORMs.
ORMs help you to think about your data as objects in your domain, instead of thinking about tables and fields and rows, so it abstracts the technical aspect of persistence and gives you a more model-driven approach while you are writting software.
I use to read a lot about domain-driven design as an architectural guide, but now here in stack overflow I've received many suggestions on using hexagonal architecture, all these patterns and practices help you to buidl better software, and I guess we will never stop learning. So yep, think about ORMs like artifacts to help you focus on more important aspects of your code rather than just making tables and querys. Hope it helps,

Should CSLA be used with a dependency injection framework?

My development team is evaluating the various frameworks available for .NET to simplify our programming, one of which is CSLA. I have to admit to being a bit confused as to whether or not CSLA would benefit from being used in conjunction with a dependency injection framework, such as Spring.net or Windsor. If we combined one of those two DI frameworks with, say, the Entity Framework to handle ORM duties, does that negate the need or benefit of using CSLA altogether?
I have various levels of understanding of all these frameworks, and I'm trying to get a big picture of what will best benefit our enterprise architecture and object design.
Thank you!
CSLA is a framework for creating business entities, so has separate concerns than an IoC container or ORM. In a enterprise application you should consider the benefits of all three.
In particular, you should consider CSLA if you want data binding built in to your models, dirty checking, N-level undo, validation and business rules, as well as the data portal implementation which allows easy configuration for n-tier deployments.
Short answer: Yes.
Long answer: It requires a bit of grunt work and some experimentation to setup, but it can be done without fundamentally breaking CSLA. I put together a working prototype using StructureMap and the repository pattern and used the BuildUp method of Setter Injection to inject within CSLA. I used a method similar to the one found here to ensure that my business objects are re-injected when the objects are serialized.
I also use the registry base class of StructureMap to separate my configuration into presentation, CSLA client, CSLA server, and CSLA global settings. This way I can use the linked file feature of Visual Studio to include the CSLA server and CSLA global configuration files within the server-side Data Portal and the configuration will always be the same in both places. This was to ensure I can still change the Data Portal configuration settings in CSLA from 2 tier to 3 tier without breaking anything.
Anyway, I am still weighing the potential benefits with the drawbacks to using DI, but so far I am leaning in the direction of using it because testing will be much easier although I am skeptical of trying to use any of the advanced features of DI such as interception. I recommend reading the book Dependency Injection in .NET by Mark Seemann to understand the right and wrong way to use DI because there is a lot of misinformation on the Internet.

EF and design pattern

I’m working on a high volume transactional enterprise application(asp.net, windows app, oracle app as client) which has been designed using n-tire application and SOA architecture .The application was developed in the .NET platform utilizing C#,VB.NET, Framework 3.5 (I’m planning to upgrade to the , Framework 4.0), EF( EF in the data layer level) and WCF(WCF services in the service layer level)
Since this is the first project using EF, and having read about using EF in n-tier and SOA applications, and the features available in the EF Feature, I have the following points:
Which design pattern should I use in EF( Simple Entities, Change Set, Self-Tracking Entities and DTOs) in the data layer level
In addition Which design pattern should I use in the other tier and layer to get the best practices of EF
Thanks
"In addition Which design pattern should I use in the other tier and layer to get the best practices of EF "
I would use the saperation of concerns using IoC at the root of my design patterns. for Data Layer Abstraction purpose I would definately go for Repository patterns. There are some interesting work which you see on the web for e.g. UnitOfWork for transactions etc.
Not sure about your knowledge in Repository pattern but here's a good start.
There is also a good project on the CodePlex called Project Silk which can give you a good heads up for both the above topics among others.
All the best

Spring.NET & Alternatives

Is Spring.NET a good framework to use in web development?
Are there alternatives?
Update (for Frederik):
Are there drawbacks when using Spring.NET (or IoC container) in Web Development. I always used spring.actionscript in client side flex applications, but client applications aren't the same as Web Applications.
Is there a Microsoft IoC Containter Framework?
How does it handle concurrency?
As a Spring.NET committer I am biased of course, but Spring.Web was entirely built and refined out of our own needs over the past years. Imho it provides the broadest support compared to other containers when it comes to WebForms development. MVC support is still TDB though.
Spring.NET itself also is entirely thread-safe. Of course your own singleton implementations need to be threadsafe, if not you can always use "request" scope.
hth,
Erich
"Is there a Microsoft IoC Containter Framework?"
- Yes, it's called Unity
Is it a good framework ? Depends on your requirements.
Are there alternatives ? Yes.
(Castle Windsor, StructureMap, PicoContainer, ...).
Google can show you the way ...