Search Results

Search found 11996 results on 480 pages for 'dependency properties'.

Page 7/480 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • How do I use constructor dependency injection to supply Models from a collection to their ViewModels

    - by GraemeF
    I'm using constructor dependency injection in my WPF application and I keep running into the following pattern, so would like to get other people's opinion on it and hear about alternative solutions. The goal is to wire up a hierarchy of ViewModels to a similar hierarchy of Models, so that the responsibility for presenting the information in each model lies with its own ViewModel implementation. (The pattern also crops up under other circumstances but MVVM should make for a good example.) Here's a simplified example. Given that I have a model that has a collection of further models: public interface IPerson { IEnumerable<IAddress> Addresses { get; } } public interface IAddress { } I would like to mirror this hierarchy in the ViewModels so that I can bind a ListBox (or whatever) to a collection in the Person ViewModel: public interface IPersonViewModel { ObservableCollection<IAddressViewModel> Addresses { get; } void Initialize(); } public interface IAddressViewModel { } The child ViewModel needs to present the information from the child Model, so it's injected via the constructor: public class AddressViewModel : IAddressViewModel { private readonly IAddress _address; public AddressViewModel(IAddress address) { _address = address; } } The question is, what is the best way to supply the child Model to the corresponding child ViewModel? The example is trivial, but in a typical real case the ViewModels have more dependencies - each of which has its own dependencies (and so on). I'm using Unity 1.2 (although I think the question is relevant across the other IoC containers), and I am using Caliburn's view strategies to automatically find and wire up the appropriate View to a ViewModel. Here is my current solution: The parent ViewModel needs to create a child ViewModel for each child Model, so it has a factory method added to its constructor which it uses during initialization: public class PersonViewModel : IPersonViewModel { private readonly Func<IAddress, IAddressViewModel> _addressViewModelFactory; private readonly IPerson _person; public PersonViewModel(IPerson person, Func<IAddress, IAddressViewModel> addressViewModelFactory) { _addressViewModelFactory = addressViewModelFactory; _person = person; Addresses = new ObservableCollection<IAddressViewModel>(); } public ObservableCollection<IAddressViewModel> Addresses { get; private set; } public void Initialize() { foreach (IAddress address in _person.Addresses) Addresses.Add(_addressViewModelFactory(address)); } } A factory method that satisfies the Func<IAddress, IAddressViewModel> interface is registered with the main UnityContainer. The factory method uses a child container to register the IAddress dependency that is required by the ViewModel and then resolves the child ViewModel: public class Factory { private readonly IUnityContainer _container; public Factory(IUnityContainer container) { _container = container; } public void RegisterStuff() { _container.RegisterInstance<Func<IAddress, IAddressViewModel>>(CreateAddressViewModel); } private IAddressViewModel CreateAddressViewModel(IAddress model) { IUnityContainer childContainer = _container.CreateChildContainer(); childContainer.RegisterInstance(model); return childContainer.Resolve<IAddressViewModel>(); } } Now, when the PersonViewModel is initialized, it loops through each Address in the Model and calls CreateAddressViewModel() (which was injected via the Func<IAddress, IAddressViewModel> argument). CreateAddressViewModel() creates a temporary child container and registers the IAddress model so that when it resolves the IAddressViewModel from the child container the AddressViewModel gets the correct instance injected via its constructor. This seems to be a good solution to me as the dependencies of the ViewModels are very clear and they are easily testable and unaware of the IoC container. On the other hand, performance is OK but not great as a lot of temporary child containers can be created. Also I end up with a lot of very similar factory methods. Is this the best way to inject the child Models into the child ViewModels with Unity? Is there a better (or faster) way to do it in other IoC containers, e.g. Autofac? How would this problem be tackled with MEF, given that it is not a traditional IoC container but is still used to compose objects?

    Read the article

  • Error deploying web application on Weblogic 10.3 using maven 2: "Can't find wsdl /wsdls/wsat.wsdl"

    - by Marcos Carceles
    Hi, I'm using maven for deploying a web application in my Weblogic 10.3 server remotely. I created my pom file based on the indication on this previous question: Using maven as build tool for Weblogic 10.3 My pom.xml file is: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.balfourbeatty.horizon.maven.test</groupId> <artifactId>maven-test-webapp</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>maven-test-webapp Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <weblogic.version>10.3</weblogic.version> </properties> <build> <plugins> <plugin> <groupId>org.apache.myfaces.trinidadbuild</groupId> <artifactId>maven-jdev-plugin</artifactId> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>weblogic-maven-plugin</artifactId> <version>2.9.1</version> <configuration> <name>maven-test-webapp</name> <adminServerHostName>******************</adminServerHostName> <adminServerPort>****</adminServerPort> <adminServerProtocol>t3</adminServerProtocol> <userId>******</userId> <password>*****</password> <upload>true</upload> <remote>true</remote> <verbose>true</verbose> <debug>true</debug> <targetNames>WLS_Spaces</targetNames> <noExit>true</noExit> <projectPackaging>war</projectPackaging> </configuration> <dependencies> <dependency> <groupId>com.sun</groupId> <artifactId>tools</artifactId> <version>1.6</version> <scope>system</scope> <systemPath>${java.home}/../lib/tools.jar</systemPath> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>weblogic</artifactId> <version>${weblogic.version}</version> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>webservices</artifactId> <version>${weblogic.version}</version> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.utils.full</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.i18n</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.weblogic.rmi.client</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>javax.enterprise.deploy</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>webserviceclient</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.weblogic.security.wls</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.weblogic.security.identity</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.weblogic.security</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>wlclient</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.transaction</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.utils.classloaders</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>wljmsclient</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.management.core</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>wls-api</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.descriptor</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.logging</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.weblogic.socket.api</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.weblogic.security.digest</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.weblogic.workmanager</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.weblogic.lifecycle</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.utils.wrapper</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>wlsafclient</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.management.jmx</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>com.bea.core.descriptor.wl</artifactId> <version>${weblogic.version}</version> <scope>provided</scope> </dependency> <dependency> <groupId>weblogic</groupId> <artifactId>javax.mail</artifactId> <version>10.3</version> </dependency> </dependencies> </plugin> </plugins> <finalName>maven-test-webapp</finalName> </build> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.codehaus.mojo</groupId> <artifactId>weblogic-maven-plugin</artifactId> <version>2.9.1</version> </dependency> </dependencies> <distributionManagement> <!-- use the following if you're not using a snapshot version. --> <repository> <id>internal</id> <name>Archiva Managed Internal Repository</name> <url>http://localhost:8180/archiva/repository/internal</url> </repository> <!-- use the following if you ARE using a snapshot version. --> <snapshotRepository> <id>snapshots</id> <name>Archiva Managed Snapshot Repository</name> <url>http://localhost:8180/archiva/repository/snapshots</url> </snapshotRepository> </distributionManagement> </project> All the dependencies are already resolved properly, as they are in the local archiva repository. The application does not contain any web-service, being just a "hello world" application. /index.jsp /WEB-INF/web.xml The error I get is: [BasicOperation.execute():423] : Initiating deploy operation for app, maven-test-webapp, on targets: [BasicOperation.execute():425] : WLS_Spaces Task 14 initiated: [Deployer:149026]deploy application maven-test-webapp on WLS_Spaces. dumping Exception stack Task 14 failed: [Deployer:149026]deploy application maven-test-webapp on WLS_Spaces. Target state: deploy failed on Server WLS_Spaces weblogic.wsee.ws.WsException: When processing WebService module 'maven-test-webapp.war'. Can't find wsdl /wsdls/wsat.wsdl at weblogic.wsee.deploy.WSEEWebModule.loadWsdlDefinitions(WSEEWebModule.java:159) at weblogic.wsee.deploy.WSEEModule.loadWsdl(WSEEModule.java:334) at weblogic.wsee.deploy.WSEEAnnotationProcessor.isWsdlHasPolicy(WSEEAnnotationProcessor.java:312) at weblogic.wsee.deploy.WSEEAnnotationProcessor.process(WSEEAnnotationProcessor.java:91) at weblogic.wsee.deploy.WSEEAnnotationProcessor.process(WSEEAnnotationProcessor.java:51) at weblogic.wsee.deploy.WSEEModule.prepare(WSEEModule.java:102) at weblogic.wsee.deploy.ServletDeployListener.contextPrepared(ServletDeployListener.java:26) at weblogic.servlet.internal.EventsManager$FireContextPreparedAction.run(EventsManager.java:503) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121) at weblogic.servlet.internal.EventsManager.notifyContextPreparedEvent(EventsManager.java:162) at weblogic.servlet.internal.WebAppServletContext.initContextListeners(WebAppServletContext.java:1782) at weblogic.servlet.internal.WebAppServletContext.prepare(WebAppServletContext.java:1136) at weblogic.servlet.internal.HttpServer.doPostContextInit(HttpServer.java:449) at weblogic.servlet.internal.HttpServer.loadWebApp(HttpServer.java:424) at weblogic.servlet.internal.WebAppModule.registerWebApp(WebAppModule.java:924) at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:356) at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:176) at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:199) at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:391) at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:83) at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:59) at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:43) at weblogic.application.internal.BaseDeployment$1.next(BaseDeployment.java:1221) at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:83) at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:367) at weblogic.application.internal.SingleModuleDeployment.prepare(SingleModuleDeployment.java:39) at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:154) at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:60) at weblogic.deploy.internal.targetserver.operations.ActivateOperation.createAndPrepareContainer(ActivateOperation.java:207) at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doPrepare(ActivateOperation.java:98) at weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:217) at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:747) at weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1216) at weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:250) at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:159) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentReceiverCallbackDeliverer.java:157) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$000(DeploymentReceiverCallbackDeliverer.java:12) at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$1.run(DeploymentReceiverCallbackDeliverer.java:45) at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:516) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201) at weblogic.work.ExecuteThread.run(ExecuteThread.java:173) Does anyone have any idea on what could the problem be? Many thanks!

    Read the article

  • Dependency Injection with Custom Membership Provider

    - by alastairs
    I have an ASP.NET MVC web application that implements a custom membership provider. The custom membership provider takes a UserRepository to its constructor that provides an interface between the membership provider and NHibernate. The UserRepository is provided by the Ninject IoC container. Obviously, however, this doesn't work when the provider is instantiated by .NET: the parameterless constructor does not have a UserRepository and cannot create one (the UserRepository requires an NHibernate session be passed to its constructor), which then means that the provider cannot access its data store. How can I resolve my object dependency? It's probably worth noting that this is an existing application that has been retrofitted with Ninject. Previously I used parameterless constructors that were able to create their required dependencies in conjunction with the parametered constructors to assist unit testing. Any thoughts, or have I built myself into a corner here?

    Read the article

  • Using Dependency Walker

    - by Valter Minute
    Dependency Walker is a very useful tool that can be used to find dependencies of a Portable Executable module. The PE format is used also on Windows CE and this means that Dependency Walker can be used to analyze also Windows CE/Windows Embedded Compact module. On Win32 it can be used also to monitor modules loaded by an application during runtime, this feature is not supported on CE. You can download dependency walker for free here: http://dependencywalker.com/. To analyze the dependencies of a Windows CE/Windows Embedded Compact 7 module you can just open it using Dependency Walker. If you want to check if a specific module can run on a Windows CE/Windows Compact 7 OS Image you can copy the executable in the same directory that contains your OS binaries (FLATRELEASEDIR). In this way Dependency Walker will highlight missing dlls or missing entry points inside existing dlls. Let’s do a quick sample. You need to check if myapp.exe (an application from a third party) can run on an image generated with your Test01 OSDesign. Copy Myapp.exe to the flat release directory of your OS Design. Launch depends.exe and use the File\Open option of its main menu to open the application executable file you just copied. You may receive an error if some of the modules required by your applications are missing. Before you analyze the module dependencies is important to configure Dependency Walker to check DLL in the same folder where your application file is stored. This is needed because some Windows CE DLLs have the same name of Win32 system DLLs but different entry points. To configure the DLL search path select “Options\Configure Module Search Order…” from Depenency Walker main menu. Select “The application directory” from the “Current Search Order” list, select it, and move it to the top of the list using the “Move Up” button. The system will ask to refresh the window contents to reflect your configuration change, click on “Yes” to proceed. Now you can inspect myapp.exe dependencies. Some DLLs are missing (XAMLRUNTIME.DLL and TILEENGINE.DLL) and OLE32.DLL exists but does not export the “CoInitialize” entry point that is required by myapp.exe. The bad news is that MyApp.exe will not run on your OS Image, the good news is that now you know what’s missing and you can add the required modules to your OS Design and fix the problem!

    Read the article

  • Circular Dependency Solution

    - by gfoley
    Our current project has ran into a circular dependency issue. Our business logic assembly is using classes and static methods from our SharedLibrary assembly. The SharedLibrary contains a whole bunch of helper functions, such as a SQL Reader class, Enumerators, Global Variables, Error Handling, Logging and Validation. The SharedLibrary needs access to the Business objects, but the Business objects need access to SharedLibrary. The old developers solved this obvious code smell by replicating the functionality of the business objects in the shared library (very anti-DRY). I've spent a day now trying to read about my options to solve this but i'm hitting a dead end. I'm open to the idea of architecture redesign, but only as a last resort. So how can i have a Shared Helper Library which can access the business objects, with the business objects still accessing the Shared Helper Library?

    Read the article

  • How far does Dependency Injection reach?

    - by Baddie
    My web app solution consists of 3 projects: Web App (ASP.NET MVC) Business Logic Layer (Class Library) Database Layer (Entity Framework) I want to use Ninject to manage the lifetime of the DataContext generated by the Entity Framework in the Database Layer. The Business Logic layer consists of classes which reference repositories (located in the database layer) and my ASP.NET MVC app references the business logic layer's service classes to run code. Each repository creates an instance of the MyDataContext object from the Entity Framework Repository public class MyRepository { private MyDataContext db; public MyRepository { this.db = new MyDataContext(); } // methods } Business Logic Classes public class BizLogicClass { private MyRepository repos; public MyRepository { this.repos = new MyRepository(); } // do stuff with the repos } Will Ninject handle the lifetime of MyDataContext despite the lengthy dependency chain from the Web App to the Data Layer?

    Read the article

  • Circular dependencies in StructureMap - can they be broken with property injection?

    - by Andy
    Hi, I've got the simplest kind of circular dependency in structuremap - class A relies on class B in its constructor, and class B relies on class A in its constructor. To break the dependency, I made class B take class A as a property, rather than a constructor argument, but structuremap still complains. I've seen circular dependencies broken using this method in other DI frameworks - is this a problem with Structuremap or am I doing something wrong? Edit: I should mention that class B's property is an array of class A instances, wired up like this: x.For<IB>().Singleton().Use<B>().Setter(y => y.ArrayOfA).IsTheDefault();

    Read the article

  • Dependency Property Set Priority: CodeBehind vs. XAML

    - by LukePet
    When I initialize a control property from code, the binding to the same property defined on XAML don't work. Why? For Example, I set control properties on startup with this statements: myControl.SetValue(UIElement.VisibilityProperty, DefaultProp.Visibility); myControl.SetValue(UIElement.IsEnabledProperty, DefaultProp.IsEnabled); and on xaml I bind the property of myControl in this way: IsEnabled="{Binding Path=IsKeyControlEnabled}" now, when the property "IsKeyControlEnabled" changes to false, myControl remains enabled (because it's initialize with true value). How can I do?

    Read the article

  • Dependency injection in constructor, method or just use a static class instead?

    - by gaetanm
    What is the best between: $dispatcher = new Dispatcher($request); $dispatcher->dispatch(); and $dispatcher = new Dispatcher(); $dispatcher->dispatch($request); or even Dispatcher::dispatch($request); Knowing that only one method of this class uses the $request instance. I naturally tend to the last solution because the class have no other states, but by I feel that it may not be the best OOP solution.

    Read the article

  • How to do dependency Injection and conditional object creation based on type?

    - by Pradeep
    I have a service endpoint initialized using DI. It is of the following style. This end point is used across the app. public class CustomerService : ICustomerService { private IValidationService ValidationService { get; set; } private ICustomerRepository Repository { get; set; } public CustomerService(IValidationService validationService,ICustomerRepository repository) { ValidationService = validationService; Repository = repository; } public void Save(CustomerDTO customer) { if (ValidationService.Valid(customer)) Repository.Save(customer); } Now, With the changing requirements, there are going to be different types of customers (Legacy/Regular). The requirement is based on the type of the customer I have to validate and persist the customer in a different way (e.g. if Legacy customer persist to LegacyRepository). The wrong way to do this will be to break DI and do somthing like public void Save(CustomerDTO customer) { if(customer.Type == CustomerTypes.Legacy) { if (LegacyValidationService.Valid(customer)) LegacyRepository.Save(customer); } else { if (ValidationService.Valid(customer)) Repository.Save(customer); } } My options to me seems like DI all possible IValidationService and ICustomerRepository and switch based on type, which seems wrong. The other is to change the service signature to Save(IValidationService validation, ICustomerRepository repository, CustomerDTO customer) which is an invasive change. Break DI. Use the Strategy pattern approach for each type and do something like: validation= CustomerValidationServiceFactory.GetStratedgy(customer.Type); validation.Valid(customer) but now I have a static method which needs to know how to initialize different services. I am sure this is a very common problem, What is the right way to solve this without changing service signatures or breaking DI?

    Read the article

  • JSR-303 dependency injection and Hibernate

    - by Jam
    Spring 3.0.2, Hibernate 3.5.0, Hibernate-Validator 4.0.2.GA I am trying to inject Spring dependencies into a ConstraintValidator using: @PersistenceContext private EntityManager entityManager; I have configured the application context with: <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/> Which, according to the Spring documentation, should allow “custom ConstraintValidators to benefit from dependency injection like any other Spring bean” Within the debugger I can see Spring calling getBean to create the ConstraintValidator. Later when flush triggers the preInsert, a different ConstraintValidator is created and called. The problem is the EntityManager is null within this new ConstraintValidator. I’ve tried injecting other dependencies within the ConstraintValidator and these are always null. Does anyone know if it is possible to inject dependencies into a ConstraintValidator?

    Read the article

  • Is dependency injection by hand a better alternative to composition and polymorphism?

    - by Drake Clarris
    First, I'm an entry level programmer; In fact, I'm finishing an A.S. degree with a final capstone project over the summer. In my new job, when there isn't some project for me to do (they're waiting to fill the team with more new hires), I've been given books to read and learn from while I wait - some textbooks, others not so much (like Code Complete). After going through these books, I've turned to the internet to learn as much as possible, and started learning about SOLID and DI (we talked some about Liskov's substitution principle, but not much else SOLID ideas). So as I've learned, I sat down to do to learn better, and began writing some code to utilize DI by hand (there are no DI frameworks on the development computers). Thing is, as I do it, I notice it feels familiar... and it seems like it is very much like work I've done in the past using composition of abstract classes using polymorphism. Am I missing a bigger picture here? Is there something about DI (at least by hand) that goes beyond that? I understand the possibility of having configurations not in code of some DI frameworks having some great benefits as far as changing things without having to recompile, but when doing it by hand, I'm not sure if it's any different than stated above... Some insight into this would be very helpful!

    Read the article

  • Maven and db4o dependency

    - by Jens Jansson
    I'm intrigued to test new frameworks in the Java world, and decided to create a new project that takes advantage of Maven and db4o. I'm starting to get a hang of Maven, but I have a hard time adding db4o as a dependency to the project. First problem is that db4o doesn't exist in the official Maven repositories. Next up comes the problem that db4o seem to have recently restructured their whole site's URI:s, so I'm getting 'site not found' messages all the time when I try to navigate their site. I found somewhere a potential Maven repository that should be at https://source.db4o.com/maven but I get all the time "Error reading archetype catalog https://source.db4o.com/maven Unable to locate resource in repository" when I try to access it. So, any suggestions on how I'll get db4o up through Maven? I've managing Maven through Eclipse with the M2Eclipse plugin.

    Read the article

  • Passing ASP.NET User by Dependency Injection

    - by UpTheCreek
    In my web application I have various components that need to access the currently authenticated user (HttpContext.User). There are two obvious ways a component can access this: 1) Accessing getting the User from HttpContext.Current 2) Passing the user around in constructors Is not ideal because it makes testing difficult and ties application components to web concerns, when they really shouldn't know about it. Is just messy and complicates everything. So I've been thinking about passing in the current user (or perhaps just the name/id) to any component that needs it using an IoC container (via dependency injection). Is anyone using this technique to supply the current ASP.NET user to parts of the application? Or, Does this sound like a sensible approach? I would like know how this has worked out for people. Thanks

    Read the article

  • it is a good approach to implement dependency injection in a desktop app?

    - by luis_laurent
    Well, the thing is that I am just about to create a Desktop App (with .NET windows forms) And now I just wonder if it would be really a wise choise to use any IoC (StructureMap,Ninject,Spring .Net), I have used them before for Asp.Net web applications but what makes me doubt now is the fact that working with windows forms my business entities will persist when I navigate through tabs and unlike than web forms or mvc apps where it would be necesary to inject my business entity for every new request that is performed, I mean this because of the Asp.Net page life cycle where is performed the initialization and controls instantiation. Maybe I am misunderstanding the point of using an IoC, so please tell me what do you think would be a better choise?

    Read the article

  • Getting 'this' pointer inside dependency property changed callback

    - by mizipzor
    I have the following dependency property inside a class: class FooHolder { public static DependencyProperty CurrentFooProperty = DependencyProperty.Register( "CurrentFoo", typeof(Foo), typeof(FooHandler), new PropertyMetadata(OnCurrentFooChanged)); private static void OnCurrentFooChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { FooHolder holder = (FooHolder) d.Property.Owner; // <- something like this // do stuff with holder } } I need to be able to retrieve a reference to the class instance in which the changed property belongs. This is since FooHolder has some event handlers that needs to be hooked/unhooked when the value of the property is changed. The property changed callback must be static, but the event handler is not.

    Read the article

  • Dependency Injection -Colloquial explanation

    - by nettguy
    Recently I was asked to express the DI in colloquial explanation. I answered : 1) I am going to a hotel.I ordered food.The hotel management asks me to clean the plates and clean the tables.So here i am a client,I am responsible for managing the service (Instantiating,executing,disposing).But DI decouples such tasks so the service consumer no need not worry about controlling the life cycle of the service. 2) He also asked is there any microsoft API follows DI ?.I answered (This was my guess) In WCF you can create a Proxy using ChannelFactory that controls the life time of your factory. for item (1) he said only 10% is correct for item(2) he said that is factory pattern not dependency injection. Actually what went wrong in my explanation (apart from my bad English) ? What is the real answers for those? I am waiting for your valuable suggestions.

    Read the article

  • Dependency problems installing wine 1.5 on ubuntu 12.04 x64

    - by Moreno
    I tried: $ sudo add-apt-repository ppa:ubuntu-wine/ppa $ sudo apt-get update $ sudo apt-get install wine1.5 result was: $ sudo apt-get install wine1.5 Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: wine1.5 : Depends: wine1.5-i386 (= 1.5.6-0ubuntu1~pulse17) E: Unable to correct problems, you have held broken packages. then I tried: $ sudo dpkg --configure -a $ sudo apt-get install -f result was: $ sudo apt-get install -f Reading package lists... Done Building dependency tree Reading state information... Done 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. after all I tried: $ sudo apt-get build-dep wine1.5 Reading package lists... Done Building dependency tree Reading state information... Done The following packages have unmet dependencies: libgnutls-dev : Depends: libgnutls26 (= 2.12.14-5ubuntu3) but 2.12.19-1 is to be installed Depends: libgnutlsxx27 (= 2.12.14-5ubuntu3) but it is not going to be installed Depends: libgnutls-openssl27 (= 2.12.14-5ubuntu3) but it is not going to be installed E: Build-dependencies for wine1.5 could not be satisfied. also tried: $ sudo apt-get install -y ia32-libs Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: ia32-libs : Depends: ia32-libs-multiarch E: Unable to correct problems, you have held broken packages. Using synaptic: using ubuntu software center (USC): Somebody can help me? Thanks. Trying again: $ sudo dpkg --configure -a $ sudo apt-get install -f Reading package lists... Done Building dependency tree Reading state information... Done 0 upgraded, 0 newly installed, 0 to remove and 14 not upgraded. $ sudo apt-get install wine1.5 Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: wine1.5 : Depends: wine1.5-i386 (= 1.5.10-0ubuntu1~pulse19+build4) E: Unable to correct problems, you have held broken packages.

    Read the article

  • How exactly does dependency injection reduce coupling?

    - by dotnetdev
    Hi, I've done plenty of reading on Dependency Injection, but I have no idea, how does it actually reduce coupling? The analogy I have of DI is that all components are registered with a container, so theyre are like in a treasure chest. To get a component, you obviously register it first, but then you would have to interrogate the treasure chest (which is like a layer of indirection). Is this the right analogy? It doesn't make obvious how the "injection" happens, though (how would that fit in with this analogy?). Thanks

    Read the article

  • FRIEND_TEST in Google Test - possible circular dependency?

    - by Mihaela
    I am trying to figure out how FRIEND_TEST works in Google Tests. http://code.google.com/p/googletest/wiki/AdvancedGuide#Private_Class_Members I am looking at the following item, trying to implement it in my code: // foo.h #include "gtest/gtest_prod.h" // Defines FRIEND_TEST. class Foo { ... private: FRIEND_TEST(FooTest, BarReturnsZeroOnNull); int Bar(void* x); }; // foo_test.cc ... TEST(FooTest, BarReturnsZeroOnNull) { Foo foo; EXPECT_EQ(0, foo.Bar(NULL)); // Uses Foo's private member Bar(). } In the code above, the piece that I can't see, is that foo_test.cc must include foo.h, in order to have access to Foo and Bar(). [Perhaps it works differently for Google ? in my code, I must include it] That will result in circular dependency... Am I missing something ?

    Read the article

  • In dependency injection, is there a simple name for the counterpart of the injected object?

    - by kostja
    In tutorials and books, I have never seen a single word describing the object that the injected object is injected into. Instead, other terms are used, like "injection point" which don't denote the object containing the injected object. And nothing I can think of sounds right, except maybe "injection target" - but I have never read it anywhere. Is there a single word or a simple expression for it, or is it like the "He-Who-Must-Not-Be-Named" from a recent fantasy book series?

    Read the article

  • Contexts and Dependency Injection(CDI)??

    - by Masa Sasaki
    WebLogic Server?????????????WebLogic Server????????6?20?????????37?WebLogic Server???@????????Contexts and Dependency Injection(CDI)?(?????????? Fusion Middleware?????? ?? ?)?????????????????Java EE 6????????CDI???????DI(Dependency Injection)?Java EE 5????????????????????CDI??DI????????????????????????????????????????????????????????CDI????????????????????(?????? Fusion Middleware?????? ??? ??) CDI?? ???????CDI???Java EE 6???????JSR299: Contexts Dependency Injection????? ?????Dependency Injection (??????)?Aspect-Oriented Programming (AOP)?Interception ??????????????????????????? CDI?????????????????????????????????????????????? ?????????????????????????????????????????? ?????????????????????????????????????????????? ???????????????????????????CDI?????????????? CDI?????????????2? ??1???CDI??????????Oracle WebLogic Server 12c????Java EE 6????????? ?????????????????2???beans.xml???????Web??????????WEB-INF/beans.xml? EJB??META-INF/beans.xml????????????CDI????????????????beans.xml???? ?????????????????????? Java EE 5?DI(Dependency Injection) Java EE 5??DI????????????????????????????????????? ?????????????????????????????????????????(@EJB? @Resource?@WebServiceRef)??? Java EE 6?CDI Java EE 6?CDI?????????????????@Inject???????????????? ???????????????????????????????????????????????????? @Qualifier????????????????? ?????????????????????????????????????????@Qualifier? ????????????·??????????????????????@JPN??????????? @Produce???????? ???????????????????? ????????·?????????????? CDI?????????????????????????????????·??????? ????????????????????????????????????????????? ???????????????? EL(Expression Language) ???????? EL????????????JSF?ManagedBean?????????????·?????????????? ??? Java EE 6?????????CDI???????????Java EE 5?DI????AOP??? ???????????????????DI, AOP???????????????? ?????????????CDI?????????????????????????????? ?????CDI?????????????????????????????????? ?????? WebLogic Server??? WebLogic Server?????????WebLogic Server?????! WebLogic Server??????(???????????) WebLogic Server???????? WebLogic Server??????

    Read the article

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