Search Results

Search found 20224 results on 809 pages for 'inversion of control (ioc)'.

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

  • The IOC "child" container / Service Locator

    - by Mystagogue
    DISCLAIMER: I know there is debate between DI and service locator patterns. I have a question that is intended to avoid the debate. This question is for the service locator fans, who happen to think like Fowler "DI...is hard to understand...on the whole I prefer to avoid it unless I need it." For the purposes of my question, I must avoid DI (reasons intentionally not given), so I'm not trying to spark a debate unrelated to my question. QUESTION: The only issue I might see with keeping my IOC container in a singleton (remember my disclaimer above), is with the use of child containers. Presumably the child containers would not themselves be singletons. At first I thought that poses a real problem. But as I thought about it, I began to think that is precisely the behavior I want (the child containers are not singletons, and can be Disposed() at will). Then my thoughts went further into a philosophical realm. Because I'm a service locator fan, I'm wondering just how necessary the notion of a child container is in the first place. In a small set of cases where I've seen the usefulness, it has either been to satisfy DI (which I'm mostly avoiding anyway), or the issue was solvable without recourse to the IOC container. My thoughts were partly inspired by the IServiceLocator interface which doesn't even bother to list a "GetChildContainer" method. So my question is just that: if you are a service locator fan, have you found that child containers are usually moot? Otherwise, when have they been essential? extra credit: If there are other philosophical issues with service locator in a singleton (aside from those posed by DI advocates), what are they?

    Read the article

  • IOC Container Handling State Params in Non-Default Constructor

    - by Mystagogue
    For the purpose of this discussion, there are two kinds of parameters an object constructor might take: state dependency or service dependency. Supplying a service dependency with an IOC container is easy: DI takes over. But in contrast, state dependencies are usually only known to the client. That is, the object requestor. It turns out that having a client supply the state params through an IOC Container is quite painful. I will show several different ways to do this, all of which have big problems, and ask the community if there is another option I'm missing. Let's begin: Before I added an IOC container to my project code, I started with a class like this: class Foobar { //parameters are state dependencies, not service dependencies public Foobar(string alpha, int omega){...}; //...other stuff } I decide to add a Logger service depdendency to the Foobar class, which perhaps I'll provide through DI: class Foobar { public Foobar(string alpha, int omega, ILogger log){...}; //...other stuff } But then I'm also told I need to make class Foobar itself "swappable." That is, I'm required to service-locate a Foobar instance. I add a new interface into the mix: class Foobar : IFoobar { public Foobar(string alpha, int omega, ILogger log){...}; //...other stuff } When I make the service locator call, it will DI the ILogger service dependency for me. Unfortunately the same is not true of the state dependencies Alpha and Omega. Some containers offer a syntax to address this: //Unity 2.0 pseudo-ish code: myContainer.Resolve<IFoobar>( new parameterOverride[] { {"alpha", "one"}, {"omega",2} } ); I like the feature, but I don't like that it is untyped and not evident to the developer what parameters must be passed (via intellisense, etc). So I look at another solution: //This is a "boiler plate" heavy approach! class Foobar : IFoobar { public Foobar (string alpha, int omega){...}; //...stuff } class FoobarFactory : IFoobarFactory { public IFoobar IFoobarFactory.Create(string alpha, int omega){ return new Foobar(alpha, omega); } } //fetch it... myContainer.Resolve<IFoobarFactory>().Create("one", 2); The above solves the type-safety and intellisense problem, but it (1) forced class Foobar to fetch an ILogger through a service locator rather than DI and (2) it requires me to make a bunch of boiler-plate (XXXFactory, IXXXFactory) for all varieties of Foobar implementations I might use. Should I decide to go with a pure service locator approach, it may not be a problem. But I still can't stand all the boiler-plate needed to make this work. So then I try this: //code named "concrete creator" class Foobar : IFoobar { public Foobar(string alpha, int omega, ILogger log){...}; static IFoobar Create(string alpha, int omega){ //unity 2.0 pseudo-ish code. Assume a common //service locator, or singleton holds the container... return Container.Resolve<IFoobar>( new parameterOverride[] {{"alpha", alpha},{"omega", omega} } ); } //Get my instance: Foobar.Create("alpha",2); I actually don't mind that I'm using the concrete "Foobar" class to create an IFoobar. It represents a base concept that I don't expect to change in my code. I also don't mind the lack of type-safety in the static "Create", because it is now encapsulated. My intellisense is working too! Any concrete instance made this way will ignore the supplied state params if they don't apply (a Unity 2.0 behavior). Perhaps a different concrete implementation "FooFoobar" might have a formal arg name mismatch, but I'm still pretty happy with it. But the big problem with this approach is that it only works effectively with Unity 2.0 (a mismatched parameter in Structure Map will throw an exception). So it is good only if I stay with Unity. The problem is, I'm beginning to like Structure Map a lot more. So now I go onto yet another option: class Foobar : IFoobar, IFoobarInit { public Foobar(ILogger log){...}; public IFoobar IFoobarInit.Initialize(string alpha, int omega){ this.alpha = alpha; this.omega = omega; return this; } } //now create it... IFoobar foo = myContainer.resolve<IFoobarInit>().Initialize("one", 2) Now with this I've got a somewhat nice compromise with the other approaches: (1) My arguments are type-safe / intellisense aware (2) I have a choice of fetching the ILogger via DI (shown above) or service locator, (3) there is no need to make one or more seperate concrete FoobarFactory classes (contrast with the verbose "boiler-plate" example code earlier), and (4) it reasonably upholds the principle "make interfaces easy to use correctly, and hard to use incorrectly." At least it arguably is no worse than the alternatives previously discussed. One acceptance barrier yet remains: I also want to apply "design by contract." Every sample I presented was intentionally favoring constructor injection (for state dependencies) because I want to preserve "invariant" support as most commonly practiced. Namely, the invariant is established when the constructor completes. In the sample above, the invarient is not established when object construction completes. As long as I'm doing home-grown "design by contract" I could just tell developers not to test the invariant until the Initialize(...) method is called. But more to the point, when .net 4.0 comes out I want to use its "code contract" support for design by contract. From what I read, it will not be compatible with this last approach. Curses! Of course it also occurs to me that my entire philosophy is off. Perhaps I'd be told that conjuring a Foobar : IFoobar via a service locator implies that it is a service - and services only have other service dependencies, they don't have state dependencies (such as the Alpha and Omega of these examples). I'm open to listening to such philosophical matters as well, but I'd also like to know what semi-authorative reference to read that would steer me down that thought path. So now I turn it to the community. What approach should I consider that I havn't yet? Must I really believe I've exhausted my options?

    Read the article

  • Stairway to Database Source Control Level 2: Getting a Database into Source Control

    In this level, we're going to continue the philosophy of learning by example, and get a database into our SVN repository. We will also consider our overall approach to source control for databases, and the manner in which our team will develop these databases, concurrently. 24% of devs don’t use database source control – make sure you aren’t one of themVersion control is standard for application code, but databases haven’t caught up. So what steps can you take to put your SQL databases under version control? Why should you start doing it? Read more to find out…

    Read the article

  • Handling dependencies with IoC that change within a single function call

    - by Jess
    We are trying to figure out how to setup Dependency Injection for situations where service classes can have different dependencies based on how they are used. In our specific case, we have a web app where 95% of the time the connection string is the same for the entire Request (this is a web application), but sometimes it can change. For example, we might have 2 classes with the following dependencies (simplified version - service actually has 4 dependencies): public LoginService (IUserRepository userRep) { } public UserRepository (IContext dbContext) { } In our IoC container, most of our dependencies are auto-wired except the Context for which I have something like this (not actual code, it's from memory ... this is StructureMap): x.ForRequestedType().Use() .WithCtorArg("connectionString").EqualTo(Session["ConnString"]); For 95% of our web application, this works perfectly. However, we have some admin-type functions that must operate across thousands of databases (one per client). Basically, we'd want to do this: public CreateUserList(IList<string> connStrings) { foreach (connString in connStrings) { //first create dependency graph using new connection string ???? //then call service method on new database _loginService.GetReportDataForAllUsers(); } } My question is: How do we create that new dependency graph for each time through the loop, while maintaining something that can easily be tested?

    Read the article

  • What's the simplest IOC container for C#?

    - by Greg
    What's the simplest IOC container for C#? Is simple to learn and get productive with for a small app. In my case a winforms app which I want to abstract the data layer for later potential migration to a web-service for the data layer.

    Read the article

  • IoC / Dependency Injection - please explain code versus XML

    - by steve.macdonald
    I understand basically how IoC frameworks work, however one thing I don't quite get is how code-based config is supposed to work. With XML I understand how you could add a new assembly to a deployed application, then change the config in XML to include it. If the application is already deployed (i.e., compiled in some form) then how can code changes be made without recompiling? Or is that what people do, just change config in code and recompile?

    Read the article

  • NHibernate + Sql Compact + IoC - Connection Managment

    - by Michael
    When working with NHibernate and Sql Compact in a Windows Form application I am wondering what is the best practice for managing connections. With SQL CE I have read that you should keep your connection open vs closing it as one would typically do with standard SQL. If that is the case and your using a IoC, would you make your repositories lifetime be singletons so they exist forever or dispose of them after you perform a "Unit of Work". Also is there a way to determine the number of connections open to Sql CE?

    Read the article

  • IoC and DI framework for .Net applications

    - by Lijo
    Hi Can you please explain how the following three are different in their intent? 1) Policy Injection Application Block 2) Structure Map IoC Managed 3) Managed Extensibility Framework In terms of the common tasks they do, which is simpler/aligned with generics and C# 3.0 ? Thanks Lijo

    Read the article

  • What IoC Containers Support Silverlight?

    - by Matt Casto
    I'm looking for a list of IoC Containers that support Silverlight. I know that Unity and Ninject work with Silverlight, but I haven't found any information that suggests that other well known containers, like StructureMap, Castle Windsor or Autofac, support Silverlight. Has anyone used these, or other, containers or compared them with the Silverlight platform in mind?

    Read the article

  • Resolving a Generic with a Generic parameter in Castle Windsor

    - by Aaron Fischer
    I am trying to register a type like IRequestHandler1[GenericTestRequest1[T]] which will be implemented by GenericTestRequestHandler`1[T] but I am currently getting an error from Windsor "Castle.MicroKernel.ComponentNotFoundException : No component for supporting the service " Is this type of operation supported? Or is it to far removed from the suppored register( Component.For(typeof( IList<).ImplementedBy( typeof( List< ) ) ) below is an example of a breaking test. ////////////////////////////////////////////////////// public interface IRequestHandler{} public interface IRequestHandler<TRequest> : IRequestHandler where TRequest : Request{} public class GenericTestRequest<T> : Request{} public class GenericTestRequestHandler<T> : RequestHandler<GenericTestRequest<T>>{} [TestFixture] public class ComponentRegistrationTests{ [Test] public void DoNotAutoRegisterGenericRequestHandler(){ var IOC = new Castle.Windsor.WindsorContainer(); var type = typeof( IRequestHandler<> ).MakeGenericType( typeof( GenericTestRequest<> ) ); IOC.Register( Component.For( type ).ImplementedBy( typeof( GenericTestRequestHandler<> ) ) ); var requestHandler = IoC.Container.Resolve( typeof(IRequestHandler<GenericTestRequest<String>>)); Assert.IsInstanceOf <IRequestHandler<GenericTestRequest<String>>>( requestHandler ); Assert.IsNotNull( requestHandler ); } }

    Read the article

  • [Update] RedGate SQL Source Control and TFSPreview

    - by andyleonard
    31 Oct 2012 Update: SQL Source Control 3.1 is available! - Andy 12 Oct 2012 Update: The SQL Source Control 3.1 update is currently unavailable. I will provide additional updates when this version is re-released. - Andy I am excited that RedGate ’s SQL Source Control now supports connectivity to TFSPreview , Microsoft ’s cloud-based Application Life Cycle Management portal. Buck Woody ( Blog | @buckwoody ) and I have written about TFSPreview at SQLBlog already: Team Foundation Server (TFS) in the...(read more)

    Read the article

  • A design pattern for data binding an object (with subclasses) to asp.net user control

    - by Rohith Nair
    I have an abstract class called Address and I am deriving three classes ; HomeAddress, Work Address, NextOfKin address. My idea is to bind this to a usercontrol and based on the type of Address it should bind properly to the ASP.NET user control. My idea is the user control doesn't know which address it is going to present and based on the type it will parse accordingly. How can I design such a setup, based on the fact that, the user control can take any type of address and bind accordingly. I know of one method like :- Declare class objects for all the three types (Home,Work,NextOfKin). Declare an enum to hold these types and based on the type of this enum passed to user control, instantiate the appropriate object based on setter injection. As a part of my generic design, I just created a class structure like this :- I know I am missing a lot of pieces in design. Can anybody give me an idea of how to approach this in proper way.

    Read the article

  • Database source control

    - by Bojan Skrchevski
    Should database files(scripts etc.) be on source control? If so, what is the best method to keep it and update it there? Is there even a need for database files to be on source control since we can put it on a development server where everyone can use it and make changes to it if needed. But, then we can't get it back if someone messes it up. What approach is best used for databases on source-control?

    Read the article

  • What version control system can manage all aspects?

    - by Andy Canfield
    A few months ago I dug into Subversion and GIT and was disappointed. They handle SOURCE CODE fine but not other aspects. For example, a web site under version control needs to manage file/directory ownership, file/directory read & write access, Access Control Lists, timestamps, database contents. and external links. Is there a version control system that can do as perfect a reversion as reloading from a month-old backup?

    Read the article

  • Are There Realistic/Useful Solutions for Source Control for Ladder Logic Programs

    - by Steven A. Lowe
    Version control for ladder logic (LL) programs for programmable logic controllers (PLCs) seems to be virtually non-existent. It may be because LL is a visual language and tends to be stored in binary files, or it may be because source code control hasn't "caught on" in process control engineering circles - or perhaps my Google-Fu is weak tonight. Do you know of any realistic and useful solutions for version control for such systems? Definitions: realistic = changes to the programs are tracked by user and subject to reversion and merges useful = the system integrates with visual LL designers, is not limited to LL from a single PLC manufacturer, and does not cost a ridiculous amount of money? Note: I have heard of people using SVN or Mercurial et al to track the binary files, but I don't think the diff/merge capabilities would display readable differences.

    Read the article

  • Choosing the right version control system for .NET projects [closed]

    - by madxpol
    I'm getting ready for my first "bigger" .NET project (ASP.NET MVC 3/4) on which I'm going to lead another 2 programmers and right now I'm choosing the right version control system for the job (plus I'm gonna use it for my future development too). My problem is that I did't use any version control system before, so I would like it to have as fast learning curve and intuitive merging as possible. So far I quickly looked at VisualSVN (I like the Visual Studio integration in it), but I'm reading everywhere how Git is awesome and dunno which one to choose (not limited to these two).. Maybe I'm ovethinking this but I like when everything goes smoothly:) I'd like to hear some opinions from people who used multiple version control systems (preferably on VS projects) what do you think is the less complicated and effective version control system for such a use (one to 5 man projects)?

    Read the article

  • You know you're a "version control avoider" if [closed]

    - by kmote
    I'm in the process of trying to introduce Version/Revision Control to a team of developers who have never used it. I'll be giving a presentation that I hope will be a persuasive explanation of the importance of Version Control -- the benefits of using it and the liabilities of avoiding it. I'd like to kick it off with an amusing but instructive list modelled after the "redneck" line of jokes. Can anyone help me add to this list? "You know you're a Version Control Avoider if..." You have a bunch of files or folders with names like Engine_05212012_works_old[2].cpp You've had to explain to your boss how you accidentally overwrote production code. I don't consider myself terribly witty, but I think a little humor could be helpful in this situation. Any ideas for how to extend this list? [Bonus points if you can suggest a better moniker than "Version Control Avoider"]

    Read the article

  • Dependency Inversion Principle

    - by Chris Paine
    I have been studying also S.O.L.I.D. and watched this video: https://www.youtube.com/watch?v=huEEkx5P5Hs 01:45:30 into the video he talks about the Dependency Inversion Principle and I am scratching my head??? I had to simplify it(if possible) to get it through this thick scull of mine and here is what I came up with. Code on the marked My_modified_code my version, code marked Original DIP video version. Can I accomplish the same with the latter code? Thanks in advance. Original: namespace simple.main { class main { static void Main() { FirstClass FirstClass = new FirstClass(new OtherClass()); FirstClass.Method(); Console.ReadKey(); //tempClass temp = new OtherClass(); //temp.Method(); } } public class FirstClass { private tempClass _LastClass; public FirstClass(tempClass tempClass)//ctor { _LastClass = tempClass; } public void Method() { _LastClass.Method(); } } public abstract class tempClass{public abstract void Method();} public class LASTCLASS : tempClass { public override void Method() { Console.WriteLine("\nHello World!"); } } public class OtherClass : tempClass { public override void Method() { Console.WriteLine("\nOther World!"); } } } My_modified_code: namespace simple.main { class main { static void Main() { //FirstClass FirstClass = new FirstClass(new OtherClass()); //FirstClass.Method(); //Console.ReadKey(); tempClass temp = new OtherClass(); temp.Method(); } } //public class FirstClass //{ // private tempClass _LastClass; // public FirstClass(tempClass tempClass)//ctor // { // _LastClass = tempClass; // } // public void Method() // { // _LastClass.Method(); // } //} public abstract class tempClass{public abstract void Method();} public class LASTCLASS : tempClass { public override void Method() { Console.WriteLine("\nHello World!"); } } public class OtherClass : tempClass { public override void Method() { Console.WriteLine("\nOther World!"); } }

    Read the article

  • IoC from start to finish

    - by Dave
    I'm quite sure that IoC is the way to go for my application. There are a ton of articles and even questions here on SO that discuss the different containers. I've read several blogs today with partial examples. I am personally leaning towards starting with the CommonServiceLocator and Unity as two way to solve the same problem -- I just need a bunch of assemblies to get data from a database, which I assume is what needs to be injected everywhere. I've yet to find any sites that really take a problem from beginning to end, with concrete code examples. For example, I've yet to find one that discusses an IServiceLocator and how to actually register it (or do whatever is required to make it known). What are your favorite posts / articles / SO questions that can take a noob from start to finish with the implementation?

    Read the article

  • Scaling Java applications - existing cluster-aware IoC frameworks?

    - by Zoltan
    Most people use some kind of an IoC framework - Guice, Spring, you name it. Many of us need to scale their applications too, so they complicate their lifes with Terracotta, Glassfish/JBoss/insertyourfavouritehere clusters. But is it really the way to go? Are you using any of the above? Here's some ideas we currently have implemented in a yet-to-be-opensourced framework, and I'd like to see what you think of it, or maybe "it's a complete ripoff of XY!". cluster-wide object replication - give it a name, and whenever you do something (in any node) on such an object, it will get replicated - with different guarantees do transparent soft-loadbalancing - simplest scenario: restful webservice method call proxied to an other node view-only node injection: inject a proxy to a "named" object, and get your calls automatically proxied to a node Would you use something like that? Is there a current, stable, enterprise-ready implementation out there?

    Read the article

  • How to replace the SharePoint date calendar control with more user friendly jQuery calendar control

    - by ybbest
    When you use the SharePoint date and time type for date of birth field, you will notice that the calendar control is extremely non-user-friendly. You can only navigate month by month as shown below. To resolve the issue, you can customize the list form page using SharePoint designer and replace the OOB calendar control with popular jQuery control. The solution works for both SharePoint 2010,2013 and office365. Here are the steps for how to achieve this. 1. Open SharePoint designer and create a New List Form called customNew and set as default form for the selected type. 2. Open style library in file explorer and copy jQuery and jQuery UI files into the style library in SharePoint site. You can download the jQuery and jQuery UI from the web and the content of the contactPersonCustomNewForm.js is as below. I use the dd/mm/yy format as my locale in Regional Settings is English(New Zealand). You need to change this if you live in another country with different date format $(document).ready(function() { $("img#ctl00_m_g_540b9a50_52dc_4400_a58d_1db99555fddf_ff41_ctl00_ctl00_DateTimeField_DateTimeFieldDateDatePickerImage").parent().hide(); $("img#ctl00_m_g_540b9a50_52dc_4400_a58d_1db99555fddf_ff41_ctl00_ctl00_DateTimeField_DateTimeFieldDateDatePickerImage").hide(); $("input#ctl00_m_g_540b9a50_52dc_4400_a58d_1db99555fddf_ff41_ctl00_ctl00_DateTimeField_DateTimeFieldDate").datepicker({ changeMonth:true, changeYear:true, showOn: "button", buttonImage: "/_layouts/images/calendar.gif", buttonImageOnly: true, defaultDate:"01/01/1970", yearRange: "c-20:c+20", dateFormat: "dd/mm/yy" }); }); In order to get the image and textbox selector above , you can open IE developer toolbar(click F12) and find the control ID as below: 3. Open SharePoint designer and edit the newly created New List Form customNew.aspx in advance mode. Then copy and paste the following links in the PlaceHolderAdditionalPageHead. <SharePoint:CssRegistration name="<%$SPUrl:~SiteCollection/Style Library/themes/ui-lightness/jquery-ui.css%>" runat="server"/> <SharePoint:ScriptLink language="javascript" name="~sitecollection/Style Library/jquery-1.10.2.js" Defer="false" runat="server"/> <SharePoint:ScriptLink language="javascript" name="~sitecollection/Style Library/jquery-ui-1.10.4.custom.min.js" Defer="false" runat="server"/> <SharePoint:ScriptLink language="javascript" name="~sitecollection/Style Library/contactPersonCustomNewForm.js" Defer="false" runat="server"/>   4. Now go to the list and click add, you will see the new calendar control as shown below

    Read the article

  • Adding IoC Support to my WCF service hosted in a windows service (Autofac)

    - by user137348
    I'd like to setup my WCF services to use an IoC Container. There's an article in the Autofac wiki about WCF integration, but it's showing just an integration with a service hosted in IIS. But my services are hosted in a windows service. Here I got an advice to hook up the opening event http://groups.google.com/group/autofac/browse_thread/thread/23eb7ff07d8bfa03 I've followed the advice and this is what I got so far: private void RunService<T>() { var builder = new ContainerBuilder(); builder.Register(c => new DataAccessAdapter("1")).As<IDataAccessAdapter>(); ServiceHost serviceHost = new ServiceHost(typeof(T)); serviceHost.Opening += (sender, args) => serviceHost.Description.Behaviors.Add( new AutofacDependencyInjectionServiceBehavior(builder.Build(), typeof(T), ??? )); serviceHost.Open(); } The AutofacDependencyInjectionServiceBehavior has a ctor which takes 3 parameters. The third one is of type IComponentRegistration and I have no idea where can I get it from. Any ideas ? Thanks in advance.

    Read the article

  • Lightcore IoC is returning the same instance when it should give a new one

    - by Anthony
    I have the following code using the lightcore IoC container. But it fails with "NUnit.Framework.AssertionException: Contained objects are equal" which indicates that the objects that should be transient, are not. Is this a bug in lightcore, or am I doing it wrong? [Test] public void JellybeanDispenserHasNewInstanceEachTimeWithDefault() { var builder = new ContainerBuilder(); builder.Register<IJellybeanDispenser, VanillaJellybeanDispenser>(); builder.Register<SweetVendingMachine>().ControlledBy<TransientLifecycle>(); builder.Register<SweetShop>(); builder.DefaultControlledBy<TransientLifecycle>(); IContainer container = builder.Build(); SweetShop sweetShop = container.Resolve<SweetShop>(); SweetShop sweetShop2 = container.Resolve<SweetShop>(); Assert.IsFalse(ReferenceEquals(sweetShop, sweetShop2), "Root objects are equal"); Assert.IsFalse(ReferenceEquals(sweetShop.SweetVendingMachine, sweetShop2.SweetVendingMachine), "Contained objects are equal"); Assert.IsFalse(ReferenceEquals(sweetShop.SweetVendingMachine.JellybeanDispenser, sweetShop2.SweetVendingMachine.JellybeanDispenser), "services are equal"); } PS: I would tag this question with "lightcore", but suddenly my reputation isn't good enough to make a new tag. Huh.

    Read the article

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