inversion-of-control

Spring injection into inner class

大城市里の小女人 提交于 2019-12-05 20:52:35
Is it possible to inject beans into inner class? For example: @Named public class outer { @Inject private SomeClass inst; // Injected correctly private static class inner { @Inject private AnotherClass instance; // Not being injected ... Edit: The "AnotherClass" is used only by inner class, so I do not want to pollute outer class with it. Additional reason to keep the declaration in the inner class is that I'll have to remove the static modifier from the inner class or add it to the outer class member if I move the AnotherClass member to the outer class. Annotations like @Inject are used only

Could not load type 'System.Reflection.IntrospectionExtensions' from assembly 'mscorlib

安稳与你 提交于 2019-12-05 19:04:25
I'm using Unity IoC (Microsoft.Practices.Unity) and I can compile fine, but I'm getting the following error at run time: Could not load type 'System.Reflection.IntrospectionExtensions' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The Unity version is: 3.0.1026.0 Is there a compatibility problem between .Net 4 and this version of Unity. Also, I get the same error when using Unity v2. If so, how might I go about resolving this issue? EDIT: Also, I've verified that mscorlib is referenced in my project. RESOLVED. Indeed I was using the .NET 4.5

Autofac Binding at Runtime

微笑、不失礼 提交于 2019-12-05 18:43:30
I currently use Autofac to do simple constructor injection without any issues. However what I would like to know is how to resolve dependencies at runtime. The example below shows multiple ways in which we can export a document. With simple constructor injection the concrete implementation of IExport is resolved at runtime. However what need to do is to resolve IExport on a user selection from a dropdown list which will happen after the construction of my container. Is there any examples of how I can achieve this? Public interface IExport { void Run(string content); } public class PDFformat :

Injecting a specific instance of an interface using Autofac

浪尽此生 提交于 2019-12-05 18:34:44
I have a controller and it receives a specific instance of an interface. The interface looks something like this: public interface IMyInterface { ... implementation goes here } And then I have some classes that implement this interface like this: public class MyClassA : IMyInterface { ... implementation goes here } public class MyClassB : IMyInterface { ... implementation goes here } In my ControllerA I have the following constructor: private ICustomerService customerService; private IMyInterface myInterface; puvlic ControllerA(ICustomerService customerService, IMyInterface myInterface) { this

Is Inversion of Control specific to OO languages?

倾然丶 夕夏残阳落幕 提交于 2019-12-05 18:22:31
问题 Another way to ask this question is: what is Inversion of Control according to you? I ask this question because the Wikipedia article on IoC has been hijacked by a non-OO explanation. This is taken from the discussion page and is from 2007: I took the liberty to completely rewrite the page, as the previous content was completely taken over by meaningless "object oriented" babble ... I don't see how Inversion of Control makes any sense outside of OO language. There are already many

Simple Injector Register All Services From Namespace

空扰寡人 提交于 2019-12-05 17:22:07
问题 My Service Interfaces has a namespace of Services.Interfaces The implementation of the Service Interfaces has a namespace of Web.UI.Services I have 2 service implementations for example IUserService which needs to register to UserService ICountryService which needs to register to CountryService This is how I currently register these services with SimpleInjector. container.Register<IUserService, UserService> (); container.Register<ICountryService, CountryService> (); Problem: If I have over

Spring bean fields injection

浪子不回头ぞ 提交于 2019-12-05 17:05:56
问题 Using Spring IoC allows to set bean properties exposed via setters: public class Bean { private String value; public void setValue(String value) { this.value = value; } } And the bean definition is: <bean class="Bean"> <property name="value" value="Hello!"> </bean> Is there any existing plugins/classes for Spring Framework that allows to directly expose bean fields as properties without defining setters? Something like this with the same bean definition: public class Bean { @Property private

Actionfilter Injection in ASP.NET MVC 5

ぃ、小莉子 提交于 2019-12-05 16:52:48
I have a simple filter. public class IsAdmin : ActionFilterAttribute, IAuthenticationFilter { private string _roleName; IBusinessIdentity _identity; public IsAdmin(string roleName, IBusinessIdentity identity) { this._roleName = roleName; this._identity = identity; } public void OnAuthentication(AuthenticationContext filterContext) { } public void OnAuthenticationChallenge(AuthenticationChallengeContext filterContext) { if (!_identity.Roles.Contains(_roleName)) filterContext.Result = new HttpUnauthorizedResult(); } } I am using Ninject. Here is my controller. I'm trying to get the injected

Linq to SQL DataContext Windsor IoC memory leak problem

一世执手 提交于 2019-12-05 15:45:26
I have an ASP.NET MVC app that creates a Linq2SQL datacontext on a per-web-request basis using Castler Windsor IoC. For some reason that I do not fully understand, every time a new datacontext is created (on every web request) about 8k of memory is taken up and not released - which inevitably causes an OutOfMemory exception. If I force garbage collection the memory is released OK. My datacontext class is very simple: public class DataContextAccessor : IDataContextAccessor { private readonly DataContext dataContext; public DataContextAccessor(string connectionString) { dataContext = new

Ninject Bind When Ancestor Of Type T

江枫思渺然 提交于 2019-12-05 15:37:42
问题 I've got a dependency chain that looks roughly like this: public class CarSalesBatchJob { public CarSalesBatchJob(IFileProvider fileProvider) { ... } } public class MotorcycleSalesBatchJob { public MotorcycleSalesBatchJob(IFileProvider fileProvider) { ... } } public class FtpFileProvider : IFileProvider { public FtpFileProvider(IFtpSettings settings) { ... } } public class CarSalesFtpSettings : IFtpSettings { ... } public class MotorcycleSalesFtpSettings : IFtpSettings { ... } Up until now, I