inversion-of-control

How can I dynamically register generic classes with a name with Unity?

℡╲_俬逩灬. 提交于 2019-12-06 02:35:14
问题 I have an assembly with a lot of classes (300+) with a BaseClass and I want register a generic class with a interface. With unity you have to register by { Name } if you want to resolve an array of objects of the interface. I want an array of objects in the MainViewModel automatically. Is there a way to automate this with reflection? Any suggestions? Example (pseudo): public class BaseClass { public void doFoo(); } public ClassNumber001 : BaseClass { } public ClassNumber002 : BaseClass { }

Configuring AutoMapper to fulfil ITypeConverter<,> constructor dependecies with Autofac

倾然丶 夕夏残阳落幕 提交于 2019-12-06 02:18:19
My first time working with Autofac to inject AutoMapper's IMapper interface into classes that have an object mapping requirement. I have made some progress, with a little help , getting the various dependencies added to AutoMapper's register using Assembly Scanning: builder.RegisterAssemblyTypes(AppDomain.CurrentDomain.GetAssemblies()) .AsClosedTypesOf(typeof(ITypeConverter<,>)) .AsImplementedInterfaces(); builder.RegisterAssemblyTypes(typeof(AutoMapperExtensions).Assembly) .AssignableTo<Profile>().As<Profile>(); builder.Register(context => { var profiles = context.Resolve<IEnumerable<Profile>

Does Funq IoC Container support property injection?

*爱你&永不变心* 提交于 2019-12-06 02:05:34
问题 I'm looking for an IoC container to use in my Compact Framework application. Trying out Funq I noticed that I can't find a way to do Property Injection with it. I've looked through the discussion on the project's site and the unit tests for it, but I can't find any example of Property Injection. Does Funq support Property Injection? 回答1: Well wouldn't that generally go something like this? myContainer.Register<IUserRepository>(() => { var myRepository = new SomeUserRepository(); myRepository

IOC with Entity Framework

纵然是瞬间 提交于 2019-12-06 01:43:31
问题 I am trying to make use of Unity Framework with Entity Framework. Let me explain the scenario. Let's say I have a Database with 5 tables. I will have 5 interfaces each of them corresponding to one table in Database having each field of table as a member. Now I want my Entity Framework generated classes to implement corresponding table interface. All navigational properties should return objects as interface references. This should allow me to resolve these entities using Unity framework to

Doesn't Spring really support Interface injection at all?

时光总嘲笑我的痴心妄想 提交于 2019-12-06 01:23:28
问题 I know that Spring doesn't supports Interface injection and I've read that many a times. But today as I came across an article about IOC by Martin Fowler (link), it seems using ApplicationContextAware in Spring is some what similar to the Interface injection. when ever Spring' context reference is required in our Spring bean, we'll implement ApplicationContextAware and will implement the setApplicationContext(ApplicationContext context) method, and we'll include the bean in the config file.

What's the state of Spring.Net?

孤人 提交于 2019-12-06 00:13:40
问题 I'm currently evaluating the technologies we want to use for our next project. It will mainly be a backend for automatic data manipulation. It has some dependencies and we can only build it on top of .Net 3.5 at the moment. Spring.net seems like a good match for our requirements, since it brings a DI container, ADO.Net helpers, NHibernate, Unit testing helpers and other goodies in one maintained package. How established is Spring.Net in the community and what's the state? It seems like being

Does DI make sense in a desktop app?

一个人想着一个人 提交于 2019-12-05 23:12:41
问题 I am about to create a Desktop App (with .NET windows forms) Essentially, I want to create an n-tier app but I also want loose coupling between layers. However, I am not very sure if this is a good approach for windows forms And now I just wonder if it would be really a wise choice 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

Two beans with the same name results in ConflictingBeanDefinitionException despite using @Primary

孤者浪人 提交于 2019-12-05 21:44:34
I have an application initializer class that is used to insert application specific data to database. @Component("applicationInitializer") public class ApplicationInitializer { @PostConstruct public void init(){ // some clever code here } } There is also DevApplicationInitializer class that is used to initialize database with some sample data on developer machine (this class is excluded when deploying production code). @Component("applicationInitializer") @Primary public class DevApplicationInitializer extends ApplicationInitializer { @PostConstruct @Override public void init(){ super.init();

Building a WinForms Application using MVC and Ninject as IoC Container

随声附和 提交于 2019-12-05 21:41:14
I am having to re-write a large WinForms application and I want to use MVC to allow increased testing capability etc. I want to also adopt Ninject as my IoC container as it is lightweight, fast and will increase the exstensibility of my application going forward. I have done a great deal of reading and I have managed to make a start on the arcitecture of this new application. However, I am not sure i have the right idea when using Ninject. The code... Starting with Program.cs and related classes... static class Program { [STAThread] static void Main() { FileLogHandler fileLogHandler = new

UnityContainer configured in web.config

我怕爱的太早我们不能终老 提交于 2019-12-05 21:04:26
I have the following code var container = new UnityContainer(); //LINE 1 container.RegisterType<ILogUtility,LogUtil>(); //LINE 2 var logger = container.Resolve<Logger>(); //LINE 3 logger.Log(LogType.Warn, "logging from container"); //LINE 4 How do I implement line 2 in web.config such that I will only have to code line 1, 3, and 4 in my code behind? I have searched every where for code example but they are not clear. Thanks Take a look at my tutorial http://netpl.blogspot.com/2011/11/unity-application-block-is-lightweight.html There's an example XML configuration: <?xml version="1.0" encoding=