Search Results

Search found 581 results on 24 pages for 'ioc'.

Page 3/24 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Why do I need an IoC container as opposed to straightforward DI code?

    - by Vadim
    I've been using Dependency Injection (DI) for awhile, injecting either in a constructor, property, or method. I've never felt a need to use an Inversion of Control (IoC) container. However, the more I read, the more pressure I feel from the community to use an IoC container. I played with .NET containers like StructureMap, NInject, Unity, and Funq. I still fail to see how an IoC container is going to benefit / improve my code. I'm also afraid to start using a container at work because many of my co-workers will see code which they don't understand. Many of them may be reluctant to learn new technology. Please, convince me that I need to use an IoC container. I'm going to use these arguments when I talk to my fellow developers at work.

    Read the article

  • IoC containers and service locator pattern

    - by TheSilverBullet
    I am trying to get an understanding of Inversion of Control and the dos and donts of this. Of all the articles I read, there is one by Mark Seemann (which is widely linked to in SO) which strongly asks folks not to use the service locator pattern. Then somewhere along the way, I came across this article by Ken where he helps us build our own IoC. I noticed that is is nothing but an implementation of service locator pattern. Questions: Is my observation correct that this implementation is the service locator pattern? If the answer to 1. is yes, then Do all IoC containers (like Autofac) use the service locator pattern? If the answer to 1. is no, then why is this differen? Is there any other pattern (other than DI) for inversion of control?

    Read the article

  • MEF = may experience frustration?

    - by Dave
    Well, it's not THAT bad yet. :) But I do have questions after Reed has pointed me at MEF as a potential alternative to IoC (and so far it does look pretty good). Consider the following model: As you can see, I have an App, and this app uses Plugins (whoops, missed that association!). Both the App and Plugins require usage of an object of type CandySettings, which is found in yet another assembly. I first tried to use the ComposeParts method in MEF, but the only way I could get this to work was to do something like this in the plugin code. var container = new CompositionContainer(); container.ComposeParts(this, new CandySettings()); But this doesn't make any sense, because why would I want to create the instance of CandySettings in the plugin? It should be in the App. But if I put it in the App code, then the Plugin doesn't magically figure out how to get at ICandySettings, even though I am using [Import] in the plugin, and [Export] in CandySettings. The way I did it was to use MEF's DirectoryCatalog, because this allows the plugin, when constructed, to scan all of the assemblies in the current folder and automagically import everything that is marked with the [Import] attribute. So it looks like this, and potentially in every plugin: var catalog = new DirectoryCatalog( "."); var container = new CompositionContainer( catalog); container.ComposeParts( this); This totally works great, but I can't help but think that this is not how MEF was intended to be used?

    Read the article

  • IoC, AOP and more

    - by JMSA
    What is an IoC container? What is an IoC/DI framework? Why do we need a framework for IoC/DI? Is there any relationship between IoC/DI and AOP? What is Spring.net/ninject with respect to IoC and AOP?

    Read the article

  • AutoFac Autowiring Conventions

    - by Johannes
    StructureMap has the ability to apply conventions when scanning. Thus IFoo = Foo, without explicit registration. Is something simular available in AutoFac? Looked around and just can't find anything helpfull. Thanks,

    Read the article

  • Having trouble getting MEF imports to be resolved

    - by Dave
    This is sort of a continuation of one of my earlier posts, which involves the resolving of modules in my WPF application. This question is specifically related to the effect of interdependencies of modules and the method of constructing those modules (i.e. via MEF or through new) on MEF's ability to resolve relationships. First of all, here is a simple UML diagram of my test application: I have tried two approaches: left approach: the App implements IError right approach: the App has a member that implements IError Left approach My code behind looked like this (just the MEF-related stuff): // app.cs [Export(typeof(IError))] public partial class Window1 : Window, IError { [Import] public CandyCo.Shared.LibraryInterfaces.IPlugin Plugin { get; set; } [Export] public CandyCo.Shared.LibraryInterfaces.ICandySettings Settings { get; set; } private ICandySettings Settings; public Window1() { // I create the preferences here with new, instead of using MEF. I wonder // if that's my whole problem? If I use MEF, and want to have parameters // going to the constructor, then do I have to [Export] a POCO (i.e. string)? Settings = new CandySettings( "Settings", @"c:\settings.xml"); var catalog = new DirectoryCatalog( "."); var container = new CompositionContainer( catalog); try { container.ComposeParts( this); } catch( CompositionException ex) { foreach( CompositionError e in ex.Errors) { string description = e.Description; string details = e.Exception.Message; } throw; } } } // plugin.cs [Export(typeof(IPlugin))] public class Plugin : IPlugin { [Import] public CandyCo.Shared.LibraryInterfaces.ICandySettings CandySettings { get; set; } [Import] public CandyCo.Shared.LibraryInterfaces.IError ErrorInterface { get; set; } [ImportingConstructor] public Plugin( ICandySettings candy_settings, IError error_interface) { CandySettings = candy_settings; ErrorInterface = error_interface; } } // candysettings.cs [Export(typeof(ICandySettings))] public class CandySettings : ICandySettings { ... } Right-side approach Basically the same as the left-side approach, except that I created a class that inherits from IError in the same assembly as Window1. I then used an [Import] to try to get MEF to resolve that for me. Can anyone explain how the two ways I have approached MEF here are flawed? I have been in the dark for so long that instead of reading about MEF and trying different suggestions, I've added MEF to my solution and am stepping into the code. The part where it looks like it fails is when it calls partManager.GetSavedImport(). For some reason, the importCache is null, which I don't understand. All the way up to this point, it's been looking at the part (Window1) and trying to resolve two imported interfaces -- IError and IPlugin. I would have expected it to enter code that looks at other assemblies in the same executable folder, and then check it for exports so that it knows how to resolve the imports...

    Read the article

  • How can I have a Windsor IoC container that can be shared amongst my classes but not shared across m

    - by Si Keep
    I am building a set of class libraries that produce office open xml based reports and I am using a static Windsor IoC container. My problem is that one possible entry point to the reporting system is via a web front end which means that the reporting systems static IoC Container is being shared amongst multiple web requests which causes exceptions as for each new request the reporting system is trying re-register components in Windsor that were already registered by an earlier request. I dont want to move the registration into the web app global.asax as my reporting system will no longer be stand-alone. How can I have a Windsor IoC container that can be shared amongst my reporting classes but not shared across multiple web requests?

    Read the article

  • How to programmatically register a component that depends on a list of already registered components

    - by Chris Carter
    I'm programmatically registering a group of services that all implement the same interface, IRule. I have another service that looks like this: public class MyService { private IEnumerable<IRule> _rules; public MyService(IEnumerable<IRule> rules){ _rules = rules; } } Hammett posted something that looked like what I wanted, http://hammett.castleproject.org/?p=257. I changed the signature to IRule[] and tried the ArrayResolver trick in the post but that didn't work for me(note, it didn't break anything either). Anyone know how to programmatically register a component like the code I posted above?

    Read the article

  • What are the best DI-IOC references for a vb.net programmer?

    - by bglenn
    I code primarily in vb.net. I've been doing basic dependency injection manually and am looking to learn more about DI/IoC and maybe use a DI/IoC framework/container like Ninject. There are lots of examples and write-ups using Java and C# code. I'm looking for the best resources for vb.net programmers. Likewise, is there a particular framework that would be easiest for a vb.net programmer to pick up?

    Read the article

  • Dependency injection and IOC containers in a closed project

    - by Puckl
    Does it make sense to assemble my project with dependency injection containers if I am the only one who will use the code of that project? The question came up when I read this IOC Article http://martinfowler.com/articles/injection.html The justification for using dependency injection in this article is that friends can reuse a class, and replace depending classes with their own classes because they get injected and not instantiated in the class. I would only use it to inject objects where they are needed instead of passing them through layers to their target. (Which is not so bad I learned here: Is it bad practice to pass instances through several layers?) (Maybe I will reuse parts of the project, who knows, but I don´t know if that is a good justification)

    Read the article

  • Database Context and Singleton injection with IoC

    - by zaitsman
    All of the below relates to a ASP.NET c# app. I have a Singleton Settings MemoryCache that reads values from database on first access and caches these, then invalidates them using SQL Service Broker message and re-reads as required. For the purposes of standard controllers, i create my Db Context in a request scope. However, this obviously means that i can't use the same context in the Settings Cache class, since that is a singleton and we have a scope collision. At the moment, i ended up with two db contexts - the Controllers get it via IoC container, whereas a Singleton just creates it's own. However, i am not satisfied with this approach (mostly due to the way i feel about two contexts, the cache doesn't set anything on the db hence concurrency is not an issue as much). What is a better way to do it?

    Read the article

  • How do the major C# DI/IoC frameworks compare?

    - by Slomojo
    At the risk of stepping into holy war territory, What are the strengths and weaknesses of these popular DI/IoC frameworks, and could one easily be considered the best? ..: Ninject Unity Castle.Windsor Autofac StructureMap Are there any other DI/IoC Frameworks for C# that I haven't listed here? In context of my use case, I'm building a client WPF app, and a WCF/SQL services infrastructure, ease of use (especially in terms of clear and concise syntax), consistent documentation, good community support and performance are all important factors in my choice. Update: The resources and duplicate questions cited appear to be out of date, can someone with knowledge of all these frameworks come forward and provide some real insight? I realise that most opinion on this subject is likely to be biased, but I am hoping that someone has taken the time to study all these frameworks and have at least a generally objective comparison. I am quite willing to make my own investigations if this hasn't been done before, but I assumed this was something at least a few people had done already. Second Update: If you do have experience with more than one DI/IoC container, please rank and summarise the pros and cons of those, thank you. This isn't an exercise in discovering all the obscure little containers that people have made, I'm looking for comparisons between the popular (and active) frameworks.

    Read the article

  • How to manage IoC containers in tests?

    - by frosty
    I'm very new to testing and IoC containers and have two projects: MySite.Website (MVC) MySite.WebsiteTest Currently I have an IoC container in my website. Should I recreate another IoC container for my test? Or is there a way to use the IoC in both?

    Read the article

  • How to not pass around the container when using IoC in Winforms

    - by L2Type
    I'm new to the world of IoC and having a problem with implementing it in a Winforms application. I have an extremely basic application Winform application that uses MVC, it is one controller that does all the work and a working dialog (obviously with a controller). So I load all my classes in to my IoC container in program.cs and create the main form controller using the container. But this is where I am having problems, I only want to create the working dialog controller when it's used and inside a using statement. At first I passed in the container but I've read this is bad practice and more over the container is a static and I want to unit test this class. So how do you create classes in a unit test friendly way without passing in the container, I was considering the abstract factory pattern but that alone would solve my problem without using the IoC. I'm not using any famous framework, I borrowed a basic one from this blog post http://www.kenegozi.com/Blog/2008/01/17/its-my-turn-to-build-an-ioc-container-in-15-minutes-and-33-lines.aspx How do I do this with IoC? Is this the wrong use for IoC?

    Read the article

  • Which single IoC/DI container would you recommend using and why?

    - by Rob G
    I'm asking this question because it's a good way to gauge how the community at large feels about the various containers/frameworks and why. Also, whilst my expertise may lie in .Net development, I am very interested in which frameworks are popular (and why) in other languages. If I feel the need to start digging into Java for instance, then I'd like to hit the ground running with good (comfortable) knowledge that I'm starting in the right direction. Does Ruby even need one with all its magnificent dynamicism? I have my own opinions on the .Net front, and will probably add my own personal favourite in an answer below, but I'm interested in all languages and opinions here. With all that in mind, could you please state only one IoC/DI framework that you use and recommend with the language of choice (Java/Ruby/.Net/Smalltalk etc.) and your reasoning for your choice, and if someone has already answered your particular flavour, then you can just vote it up and add comments to it so that anyone looking for advice in future and see which frameworks are more than likely to work for them once they read your reasoning. I'm hoping that over time, the best ones will bubble up to the top. I realise that this question doesn't have only one correct answer, so I won't be choosing one - the community will decide which framework gets the most votes and why. Of course, if you really feel strongly opposed to a particular brand, you could take the reputation hit and vote it down too, and this question can serve as a true wiki-style entry for research into this field. Remember, only one IoC per answer you write please - if you feel the need to promote two frameworks, then write two answers with your reasoning inside for each choice - then others in the community can agree or disagree with you.

    Read the article

  • How should I be using IoC in this winform piece of code?

    - by Pure.Krome
    Hi folks, I've got a winform app in visual studio 2010. My app does the following Get a list of files which I need to read the data then insert into a database. For each file, read data and insert into DB. So .. this is the code i have. var list = _repository.GetFileList(); if (list != null) { int i = 0; foreach(var file in list) { i++; var service = new MyService(i, _repository); service.ParseAndSave(); } } So i was hoping to have a new repository for each 'service' i create. Firstly, i'm not sure if I should be using IoC in this case. I believe I should be because then i don't need to tightly couple this winform to a repository. Secondly, I've tried using a Singleton repo, which I don't want and can confirm that it kills that code (crashes with an exception). Some other notes (which shouldn't impact this question) - Using Entity Framework for ASP.NET 4. - Using StructureMap for IoC Can someone help, please?

    Read the article

  • Talks Submitted for Ann Arbor Day of .NET 2010

    - by PSteele
    Just submitted my session abstracts for Ann Arbor's Day of .NET 2010.   Getting up to speed with .NET 3.5 -- Just in time for 4.0! Yes, C# 4.0 is just around the corner.  But if you haven't had the chance to use C# 3.5 extensively, this session will start from the ground up with the new features of 3.5.  We'll assume everyone is coming from C# 2.0.  This session will show you the details of extension methods, partial methods and more.  We'll also show you how LINQ -- Language Integrated Query -- can help decrease your development time and increase your code's readability.  If time permits, we'll look at some .NET 4.0 features, but the goal is to get you up to speed on .NET 3.5.   Go Ahead and Mock Me! When testing specific parts of your application, there can be a lot of external dependencies required to make your tests work.  Writing fake or mock objects that act as stand-ins for the real dependencies can waste a lot of time.  This is where mocking frameworks come in.  In this session, Patrick Steele will introduce you to Rhino Mocks, a popular mocking framework for .NET.  You'll see how a mocking framework can make writing unit tests easier and leads to less brittle unit tests.   Inversion of Control: Who's got control and why is it being inverted? No doubt you've heard of "Inversion of Control".  If not, maybe you've heard the term "Dependency Injection"?  The two usually go hand-in-hand.  Inversion of Control (IoC) along with Dependency Injection (DI) helps simplify the connections and lifetime of all of the dependent objects in the software you write.  In this session, Patrick Steele will introduce you to the concepts of IoC and DI and will show you how to use a popular IoC container (Castle Windsor) to help simplify the way you build software and how your objects interact with each other. If you're interested in speaking, hurry up and get your submissions in!  The deadline is Monday, April 5th! Technorati Tags: .NET,Ann Arbor,Day of .NET

    Read the article

  • Dependency Injection Confusion

    - by James
    I think I have a decent grasp of what Dependency Inversion principle (DIP) is, my confusion is more around dependency injection. My understanding is the whole point of DI is to decouple parts of an application, to allow changes in one part without effecting another, assuming the interface does not change. For examples sake, we have this public class MyClass(IMyInterface interface) { public MyClass { interface.DoSomething(); } } public interface IMyInterface { void DoSomething(); } How is this var iocContainer = new UnityContainer(); iocContainer.Resolve<MyClass>(); better practice than doing this //if multiple implementations are possible, could use a factory here. IMyInterface interface = new InterfaceImplementation(); var myClass = new MyClass(interface); It may be I am missing a very important point, but I am failing to see what is gained. I am aware that using an IOC container I can easily handle an objects life cycle, which is a +1 but I don't think that is core to what IOC is about.

    Read the article

  • how to implement IOC without a global static service?

    - by Michel
    Hi, we want to use Unity for IOC. All i've seen is the implementation that there is one global static service which holds a reference to the Unity container, which registers all interface/class combinations and every class asks that object: give me an implementation for Ithis or IThat. Frequently i see a response that this pattern is not good because it leads to a dependency from ALL classes to this service. But what i don't see often, is: what is the alternative way? Michel

    Read the article

  • Can I have conditional construction of classes when using IoC.Resolve ?

    - by Corpsekicker
    I have a service class which has overloaded constructors. One constructor has 5 parameters and the other has 4. Before I call, var service = IoC.Resolve<IService>(); I want to do a test and based on the result of this test, resolve service using a specific constructor. In other words, bool testPassed = CheckCertainConditions(); if (testPassed) { //Resolve service using 5 paramater constructor } else { //Resolve service using 4 parameter constructor //If I use 5 parameter constructor under these conditions I will have epic fail. } Is there a way I can specify which one I want to use?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >