ioc-container

Generic repository lifetime configuration with Windsor

谁都会走 提交于 2019-12-06 08:25:09
I'm out of ideas how to configure right Windsor container for use with repositories in Windows app. I have generic repository implementation Repository, where T is entity type, it has a dependency IDatacontextProvider, which provides datacontext for it: public class Repository<T> : IRepository<T> where T : class { protected DataContext DataContext; public Repository(IDataContextProvider dataContextProvider) { DataContext = dataContextProvider.DataContext; } .... } And for simple things everything works ok with following configuration: container.Register( Component.For<IDataContextProvider>()

How to keep track of all the @Autowired stuff while using Spring IoC?

杀马特。学长 韩版系。学妹 提交于 2019-12-06 06:42:28
问题 On Spring @Autowired usage question most of the people answer they prefer not using configuration files, if possible. It seems like a good answer at the first glance. However, once you have quite a big application which uses Spring IoC and autowires all the stuff using annotations @Autowired, @Service, etc. you must hit this problem: you no longer are able to keep track of your bean dependencies. How do you deal with that? Using SpringSource Tool Suite one can create graphs of dependencies on

Using Unity in WPF

半世苍凉 提交于 2019-12-06 06:37:56
问题 I have Unity 2.0 working well within the App.xaml.cs to register and resolve within that class. The question I have is regarding a best practice. I have a number of User Controls and other classes that also need to resolve some of the same and new Interface <-> implementations. The problem is theres no way to access the Unity container I created in the App.xaml.cs. I cannot use constructor or property injection to pass on the container reference. Just too many (its a large project) The user

Multiple RegisterAll registrations using the same set of singletons with SimpleInjector

一个人想着一个人 提交于 2019-12-06 06:07:25
I'm building a plugin system for an e-commerce project with Simple Injector. I'm using RegisterAll to register all implementation of a IPaymentProvider and of a IResourceRegistrar (and in the fure more). But this creates a new instance each time. Here is it suggested to use RegisterSingle on each type. But how to achieve this in this case? private static void RegisterMultipleUnderOneInterface( Container container, string name) { IEnumerable<Type> pluginRegistrations = from dll in finder.Assemblies from type in dll.GetExportedTypes() where type.GetInterfaces().Any(i => i.Name == name) where

IoC comparisions [closed]

江枫思渺然 提交于 2019-12-06 05:27:27
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago . Which IoC to consider while developing ASP.NET Web application project and what are the advantages of different IoC? ObjectBuilder Unity Spring.NET 回答1: It is not in your list but consider looking at Castle

Is having a wrapper for your IoC a good idea?

≡放荡痞女 提交于 2019-12-06 05:19:05
I have been using StructureMap for more than a year now. And all this time I used to have a wrapper class called IoC which looked like this class IoC { public static T GetInstance<T>() { return (T)GetInstance(typeof(T)); } public static IEnumerable<T> GetAllInstances<T>() { return ObjectFactory.GetAllInstances<T>(); } public static IEnumerable GetAllInstances(Type type) { return ObjectFactory.GetAllInstances(type); } public static object GetInstance(Type type) { return ObjectFactory.GetInstance(type); } public static void Inject<T>(T obj) { ObjectFactory.Inject(obj); } } I added the wrapper

Resolve one of multiple registrations with DryIoc

女生的网名这么多〃 提交于 2019-12-06 04:45:49
Given the small example below, is there a way to mark (attribute, name convention,... ) the MyInterface argument in MyService2 , so that it will resolve correctly, or is the only way to pass in MyInterface[] ? I know that Castle Windsor can resolve it based on naming convention, but I haven't found something similar in DryIoc public interface MyInterface { } public class MyImplementationA : MyInterface { } public class MyImplementationB : MyInterface { } public class MyService1 { public MyService1(MyInterface[] implementations) { Console.WriteLine(implementations.GetType().Name); } } public

How to mix decorators in autofac?

我怕爱的太早我们不能终老 提交于 2019-12-06 04:45:04
问题 I'd like to be able to mix and match decorators with Autofac. For example, let's say I have an IRepository interface, implemented by the Repository class. I could have the following decorators: RepositoryLocalCache, RepositoryDistributedCache, RepositorySecurity, RepositoryLogging..., you get the ideea. Based on config settings, I'd like to decorate the basic implementation with the needed decorators. That can be none, one or multiple decorators. I am familiar with the syntax of registering

How to provide ASP.NET MVC2 master pages with a model indepdent of the controller

瘦欲@ 提交于 2019-12-06 04:11:49
I'm using strongly typed views and autofac for Dependency Injection under ASP.NET MVC2 and I'm trying to get a common dynamic header via dependency injection. I.e. i want this to happen without the view having to be away of this content even existing and i was hoping to avoid static discovery of the container and manual resolution, but I can't find a way to easily inject the master or a partial view included in the master via either ctor or property injection. I can't imagine this is an uncommon task, but all I can find in terms of methods is Controller subclassing to stuff data into untyped

Alternative to passing IOC container around

夙愿已清 提交于 2019-12-06 03:38:10
I had the following base class with several dependencies: public abstract class ViewModel { private readonly ILoggingService loggingService; public ViewModel( ILoggingService loggingService, ...) { this.loggingService = loggingService; ... } } In my derived class, I don't want to have to repeat all of the parameters in this base class constructor, so I did this: public abstract class ViewModel { private readonly IUnityContainer container; private ILoggingService loggingService; ... public ViewModel(IUnityContainer container) { this.container = container; } public ILoggingService LoggingService