Suppose I have two types, TypeA and TypeB, that I want to register with Unity. TypeB depends on TypeA so I want to inject TypeA into type B through constructor injection. So I would like to write something like the following and have Unity be smart enough to cascade the resolution for me:
_container.RegisterType<ITypeA, TypeA>();
_con...
Should I do something along the lines of this? I'm thinking of all my controllers inheriting from BaseController. Does this break the design pattern of IoC? What else should I do instead?
public class BaseController: Controller
{
protected ICookieService CookieService {
get {
return ServiceResolver.Resolve<ICooki...
I am early in development on a new ASP.Net MVC project and I using this project to get into DI. I'm pretty sure that I am going to go with Structure Map, but that isn't what I am asking about. What I am trying to figure out is how best to organize my solution. Do both the unit test project and the model get a configuration file to map th...
I'd like to use MEF for instantiating the dependencies in an application that has several WCF services hosted in IIS. The different services depend on shared components and I'd like MEF to manage the instantiation and injection of these.
Where should I perform composition? Initially I thought of having a CompositionContainer in an IInst...
I understand what IoC containers are and have been reading up on Structure Map. The technology seems easy enough to use. My question is, what is the appropriate level of granularity for using an IoC container?
I see the following possible levels of application for IoC:
Break every dependency between all objects - certainly overkill.
...
We have developed a product (Core). We extend and override functioanlity in Core to create bespoke applications (Product).
Product has a reference to Core so it can inherit from the base forms and override the functionality.
Would MEF be n advantage here or is it more for plug-ins?
Thanks,
B
...
I'm finally wrapping my head around IoC and DI in C#, and am struggling with some of the edges. I'm using the Unity container, but I think this question applies more broadly.
Using an IoC container to dispense instances that implement IDisposable freaks me out! How are you supposed to know if you should Dispose()? The instance migh...
I'm trying to do something rather... unique, and maybe there's a far better way to do it but... I'm doing an inversion of control(ish) system that uses extension methods to enable/disable components of the class, so before I get into more detail and confuse you, lets look at some code!
using TestComponents.CommunicationProtocols.RS232; ...
I'm adding some logic to my web app to lookup geo-coordinates for a user, store them, then using those coordinates lookup the timezone and store that. My first go at this was to add a GeoCodeUser() method to a MappingService i had defined to do other map-related tasks. Because looking up the two bits of data relied on two different REST ...
DI/IOC: There are so many frameworks and the examples quickly get sticky with details particular to that framework. I find that I often learn a new technology best if I can learn its principles outside of a framework (the forest obscuring the trees).
My question: What are the simple principles of DI/IOC? I am looking for a (framework a...
Given
public class Blah : IBlah
{
public Blah(decimal argument)
{
}
}
When
ForRequestedType<IBlah>()
.TheDefault.Is.OfConcreteType<Blah>()
.WithCtorArg("argument")
.EqualToAppSetting("argument_app_setting_key")
Then StructureMap throws the following exception
No Default Instance defined for PluginFamily Sy...
Issue
I am using Castle Windsor as an IoC container in a Castle Monorail project. I would like to inject the current instance of IRailsEngineContext into an object being resolved from the container in a controller.
Context
The object I would like inject the rails context into would be used to wrap the session object for the purpose...
If I understand correctly, the typical mechanism for Dependency Injection is to inject either through a class' constructor or through a public property (member) of the class.
This exposes the dependency being injected and violates the OOP principle of encapsulation.
Am I correct in identifying this tradeoff? How do you deal with this ...
Is there a good way to get my IoC to resolve dependencies on views? I have my own IoC resolver based on Castle Windsor. I have a IResourceService that I would like to have access in my views to resolve some strings.
...
hi there,
i´m currently dealing with an issue where i have a lot of iterfaces and their implementations all created with unity. those classes contain some methods that throw exceptions on a regular base and i wanted to create a dynamic proxy around those classes so i can catch all exceptions occured in methods do handle them somewhere e...
What factors do you weigh in your decision process when you select an embedded scripting, and can issues of configuration and variation be overcome purely with IOC and the Plugin pattern?
Many times the Strategy Pattern and Decorator Pattern are good way to tame variation in domain logic. The problem set I am faced with is that calcula...
(NOTE: I've updated this question from the initial inquiry about child containers towards creating components on-demand)
Here's my design problem: I'm using the Windsor container for the main application workflow, but I have certain actions I need to create on-demand (for example, when the user clicks on a menu item). I want these actio...
Hi,
I currently have a home-made IoC container that I will soon replace with a new one. My home-made IoC container is configured using config files. From what I have read on the net, the ability to "configure from code" seems to be a very popular feature.
I don’t like the idea of having a class that knows every other class in the syste...
I am currently writing an open source SDK for a program that I use and I'm using an IoC container internally(NInject) to wire up all my internal dependencies.
I have some objects that are marked as internal so that I don't crowd the public API as they are only used internally and shouldn't been seen by the user, stuff like factories a...
Hi all,
I'm in the beginning phases of a Blackberry/J2ME project -- and along with other limitations that come with this wonderful platform, the lack of support for reflection and 1.3 language level mean that the vast majority of existing IoC containers are unusable. (Google has Guice for Android with no AOP, but even that requires sup...