dependency-injection

Enterprise Library - Get value from ParameterValue Expression

喜夏-厌秋 提交于 2019-12-13 05:03:32
问题 I am trying to convert Enterprise Library TypeRegistration ConstructorParameters to a collection of key/value pair (a HashTable or an IDictionary in general). The ConstructorParameters property is an IEnumerableOf(ParameterValue) so my problem is how to extract the values from each ParameterValue object. Every ParameterValue object contains a Type and an Expression. For ex. if a ParameterValue contains: "EventLoggingEnabled = false" then I can get the key (which is the EventLoggingEnabled)

Dependency injection with Laravel Facade

此生再无相见时 提交于 2019-12-13 05:01:30
问题 I have an error class which I have made a Facade and a ServiceProvider for. I use it like this: Err::getLastError(); I have also another class for file validation: FileValidate::IsImage($this->getUpload()); I want to inject the Err facade into the FileValidate so that I use it like this: FileValidate::Error()->getLastError(); How should I do this? Now My approach is that, in FileValidate class I add a member: function Error() { return $this; } Though the above just returns the FileValidate

POO and Interface (in C#)

邮差的信 提交于 2019-12-13 04:51:31
问题 I need to understand Interface : I have this structure : Core (contain Interface) BLL (Contain object who implement interface DAL (Contain Data access) IHM (Call BLL object) For example, i have an Interface Core.IVehicle who describe a basic vehicle like : Color Speed And a one method : LoadVehicle(int id) //return a iVehicule with speed and color In my BLL, I have an object "BLL.Car" who implement "Core.IVehicle". So, i will have a LoadVehicle method and access to DALfor get basics

Autofac Registering Multiple Containers

梦想的初衷 提交于 2019-12-13 04:34:18
问题 I have a MVC application, and i am using Autofac to resolve dependencies. I have a situation where i have to create 2 containers and runtime should decide which container to use based on a condition. The condition is if the controller Home is called, i need to use container1, or else i have to use container2. Application_Start is the place where I register the container. I am not sure how to make this happen at runtime. Any help is highly appreciated. Thanks 回答1: One reason for letting

Inject ISession into custom valueresolver

孤人 提交于 2019-12-13 04:32:33
问题 I'm trying to inject an instance of ISession into a custom AutoMapper ValueResolver . Here's the resolver public class ContactTypeResolver : ValueResolver<Common.Models.ContactType, Models.ContactType> { ISession _session; public ContactTypeResolver(ISession session) { _session = session; } protected override Models.ContactType ResolveCore(Common.Models.ContactType source) { return _session.Load<Models.ContactType>(source.Id); } } I have a profile for setting up AutoMapper this.CreateMap

ClassNotFoundException: Attempted to load class “TwigExtension” from the global namespace

帅比萌擦擦* 提交于 2019-12-13 04:26:28
问题 I'm trying to create a Twig Extension using the service container, but i'm getting a "ClassNotFoundException". Here the exception: ClassNotFoundException: Attempted to load class "TwigExtension" from the global namespace in \path\to\symfony-simple-blog\src\YagoQuinoy\SimpleBlogBundle\Twig\BlogExtension.php line 11. Did you forget a use statement for this class? Perhaps you need to add a use statement for one of the following: Symfony\Bundle\TwigBundle\DependencyInjection\TwigExtension Here

Why Autowired on irrelevant method is ignored

こ雲淡風輕ζ 提交于 2019-12-13 04:26:10
问题 What happens when you use @Autowired on irrelevant method, as @Test in Spring context: @Autowired @Test public void testDao() { assert("something", dao.read()); } It seems that nothing happens and Test succeeded, is there a way getting an error/warning in such case? For auto wiring a field I'm getting expected exception, e.g. @Autowired String nothing; Produces an exception: FAILED CONFIGURATION: @BeforeClass springTestContextPrepareTestInstance org.springframework.beans.factory

HashMap of Retrofit Classes with Dagger

旧巷老猫 提交于 2019-12-13 04:19:23
问题 I'm kinda new to Dependency Injection and I have a doubt. In my app I have a HashMap to store built classes (like a cache) for RetroFit, but now I'm moving to DI with Dagger and I'd like to know how can I achieve the same behaviour. My code: private Map<String, Object> restInstances; public <T> T getRestClient(Class<T> clazz) { T client = null; if ((client = (T) restInstances.get(clazz.getCanonicalName())) != null) { return client; } client = restAdapter.create(clazz); restInstances.put(clazz

Ioc/DI - Why do I have to reference all layers/assemblies in application's entry point?

折月煮酒 提交于 2019-12-13 04:17:23
问题 (Related to this question, EF4: Why does proxy creation have to be enabled when lazy loading is enabled?). I'm new to DI, so bear with me. I understand that the container is in charge of instantiating all of my registered types but in order to do so it requires a reference to all of the DLLs in my solution and their references. If I weren't using a DI container, I wouldn't have to reference the EntityFramework library in my MVC3 app, only my business layer, which would reference my DAL/Repo

Field @Inject not working in Dagger2

蹲街弑〆低调 提交于 2019-12-13 04:16:06
问题 I am new to CDI with Dagger. I have the following structure. The issue is when I go to fetch backendService in class Main, only the direct backendService is fetched, but the underlying User dependency remains null. Is there anything wrong with this setup. Class MyComponent import javax.inject.Singleton; import dagger.Component; @Singleton @Component(modules = {UserModule.class, BackEndServiceModule.class}) public interface MyComponent { User user(); BackendService backendService(); void