dependency-injection

“@inject”-ed attribute remains null

社会主义新天地 提交于 2019-12-21 07:15:08
问题 I am trying to inject a service into my bean but it is always null . I get the following error: WELD-001000 Error resolving property userBean against base null. Some code snippets: index.xhtml <h:body> Hello from Facelets #{userBean.name} </h:body> userbean.java package beans; import Domain.User; import java.io.Serializable; import javax.enterprise.context.SessionScoped; import javax.inject.Inject; import javax.inject.Named; import service.UserService; @Named @SessionScoped public class

Import org.springframework cannot be resolved

那年仲夏 提交于 2019-12-21 06:59:18
问题 I'm trying to create a simple HelloWorld application with Spring DI. I created a Java project and imported some tutorial classes, one of which is simple this: package helloworld; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader; import java.io.FileInputStream; import java.util.Properties; public class HelloWorldSpring { public static

ASP.NET Core initialize singleton after configuring DI

拟墨画扇 提交于 2019-12-21 06:47:37
问题 So let's say I have a singleton class instance that I register in the DI like this: services.AddSingleton<IFoo, Foo>(); And let's say the Foo class has a number of other dependencies (mostly repository classes that allow it to load data). With my current understanding, the Foo instance is not created until it's first used (asked). Is there a way to initialize this class other than the constructor? Like right after ConfigureServices() completes? Or should the initialization code (loading data

How do I make sure that there is one NHibernate ISession per request using Autofac?

邮差的信 提交于 2019-12-21 05:48:28
问题 I have the following code in an Autofac Module that is used in my Application_Start method: builder.Register(c => new Configuration().Configure().BuildSessionFactory()) .SingletonScoped(); builder.Register(c => c.Resolve<ISessionFactory>().OpenSession()) .HttpRequestScoped(); builder.Register<NHibernateSomethingRepository>().As<ISomethingRepository>(); The constructor for the repository takes an ISession as argument. But I end up with one session for the whole application, even though I

WPF Prism Inject same viewmodel instance into two views

╄→尐↘猪︶ㄣ 提交于 2019-12-21 05:43:04
问题 So I have two separate views in a WPF Prism app. How can I inject the same instance of a ViewModel into both the views via Dependency Injection? 回答1: (I assume you are using Unity as you mentioned DI directly and are not saying "Import" or similar) Hi, You will have to register the ViewModel as a singleton (using a ContainerControlledLifetimeManager) in the container and have it injected as usual. This ensures that you will get the same instance whenever you request for it. A valid approach

Using Castle Windsor child containers to resolve a type with a specific instance

自闭症网瘾萝莉.ら 提交于 2019-12-21 05:41:15
问题 I'm currently using Castle Windsor's child container functionality to override the registration of a particular type with a specific instance in a factory method. I am using the child containers purely so that the registration is temporary for a single resolution - in other words, I don't want the registration to affect all resolutions for that type. Perhaps some code will explain what I mean. I have a Func which acts as a factory Func<IReportCategory, IReportCategoryViewModel> - I give it an

Lazy resolution of dependency injection

 ̄綄美尐妖づ 提交于 2019-12-21 05:28:04
问题 I have .net classes I am using unity as IOC for resolving our dependencies. It tries to load all the dependencies at the beginning. Is there a way (setting) in Unity which allows to load a dependency at runtime? 回答1: There's even better solution - native support for Lazy<T> and IEnumerable<Lazy<T>> in the Unity 2.0. Check it out here. 回答2: I have blogged some code here to allow passing 'lazy' dependencies into your classes. It allows you to replace: class MyClass(IDependency dependency) with

Massive controller constructor argument list when using DI in MVC

╄→尐↘猪︶ㄣ 提交于 2019-12-21 05:27:40
问题 I am working on ASP.NET MVC3 solution that uses dependency injection with autofac. Our controllers are being created by autofac and properly and all required objects are being properly passed in. Those objects usually include services, repositories, and mappers converting domain object to MVC (view) models. So the controller constructor looks somewhat like: public abcController( ILogger logger, IabcRepository abcRepository, IabcService abcService, IMapper<AbcDomain, AbcViewModel> abcMapper, .

How do I include or autoload external libraries in a TYPO3 Extbase Extension? + Dependecy Injection?

你离开我真会死。 提交于 2019-12-21 05:27:24
问题 I'm developing a TYPO3 4.6 Extension with Extbase 1.4 and im trying to include an external library. The library, in my case the facebook PHP SDK, is under $_EXTKEY/Resources/PHP/facebook-php-sdk/facebook.php . I would like the library to autoload and automatically inject (Dependecy Injection) where I need it. Some comments I found online suggest that one should include libraries with require_once(): http://forge.typo3.org/issues/33142 if it's just a tiny helper library, it's intended to be

Entity Framework 4 DB-First Dependency Injection?

瘦欲@ 提交于 2019-12-21 05:25:13
问题 I prefer creating my own DB, setting up indexes, unique constraints etc. Generating the domain model from the database is a cinch with the edmx Entity Framework designer. Now I'm interested in setting up some repositories an using Dependency Injection. I've looked at some articles and posts on StackOverflow and seem to focus on the code-first approach. It is pretty slick how you can create a generic repository to handle the CRUD and use Dependency Injection to choose the implementation