Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code your own IOC Container

Has anyone out there written their own IOC Container in C#? Or do the vast majority of folks use the various frameworks such as Spring. What are the pro's and con's of each?

like image 243
Peanut Avatar asked Dec 22 '08 15:12

Peanut


People also ask

How is IoC container created?

The Spring IoC container makes use of Java POJO classes and configuration metadata to produce a fully configured and executable system or application. Spring provides the following two distinct types of containers. Sr.No. This is the simplest container providing the basic support for DI and is defined by the org.

What is IoC container in C#?

IoC means that one code calls another; DI goes beyond that and implements IoC by using composition. A DI or IoC container needs to instantiate objects (dependencies) and provide them to the application. To do so, it must deal with constructor injection, setter injection, and interface injection.

Should I use IoC container?

The most valuable benefit of using an IoC container is that you can have a configuration switch in one place which lets you change between, say, test mode and production mode. For example, suppose you have two versions of your database access classes...


2 Answers

It's a good excercise to write your own but in the end you might want to use an existing container. You could start with this one in 15 lines of code.

like image 80
Cristian Libardo Avatar answered Sep 29 '22 10:09

Cristian Libardo


I liked this 33 line container implementation from Ken Egozi inspired by Ayende's 15 liner

like image 28
Ruben Bartelink Avatar answered Sep 29 '22 12:09

Ruben Bartelink