ioc-container

Is having a wrapper for your IoC a good idea?

瘦欲@ 提交于 2019-12-07 13:36:44
问题 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

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

孤者浪人 提交于 2019-12-07 12:02:54
问题 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

Using StructureMap, is one of these project organizations better than another?

半世苍凉 提交于 2019-12-07 10:13:44
问题 I'm starting to work with StructureMap on a windows application project. In working on learning the basics, I found 2 ways to arrange my solution that accomplish the same goal, and I'm wondering if anyone can comment on if one of these 2 seems like a better option, and why. The goal here was to use IOC so that I could use 2 services without taking dependencies on them. So I I created interfaces in my Business Layer, and then implemented those interfaces in my Infrastructure project and

Registering generic decorators in Windsor [duplicate]

独自空忆成欢 提交于 2019-12-07 09:01:15
问题 This question already has answers here : How can I register a generic decorator using Castle Windsor? (2 answers) Closed 3 years ago . I have an interface that looks like this: public interface IQueryHandler<in TQuery, out TResult> where TQuery : IQuery<TResult> { TResult Handle(TQuery query); } I want to wrap all my handlers with this caching decorator: public class CachingQueryHandler<TQuery, TResult> : IQueryHandler<TQuery, TResult> where TQuery : IQuery<TResult> { public

Error when using DependencyResolver for Controller instantiation with MVC 3

点点圈 提交于 2019-12-07 09:01:12
问题 I'm using MVC 3 and using the following code when the application starts... UnityContainer container = new UnityContainer(); new UnityMappings(container); DependencyResolver.SetResolver(new UnityServiceLocator(container)); Now when the app runs I'm getting the following error (but only sometimes)... Activation error occured while trying to get instance of type IControllerFactory, key "" Interestingly, if I continue with the web request, the website works normally. Any ideas? I can't see what

AutoMapper with Ninject

廉价感情. 提交于 2019-12-07 08:47:32
问题 I've been trying to setup AutoMapper to instantiate all objects via Ninject. I've got the following code in my global.asax file Mapper.Configuration.ConstructServicesUsing(x => kernel.Get(x)); And as an example I have the following mapping Mapper.CreateMap<TestModel, IndexViewModel>(); However, this does not appear to be working. I get an error that 'IndexViewModel' does not have a default constructor. I can get the mapper to work by explicitly telling automapper to use ninject in the mapping

Can the object created in IoC container be called Singleton. If not - why?

久未见 提交于 2019-12-07 08:38:46
问题 can the object created in IOC container can be called Singleton if yes why if no why? Can anybody explain me in detail in simple words how IOC conatiner exactly manages the objects.. 回答1: You can say that a spring singleton is not a singleton. Singleton has its meaningful scope, the spring singleton scope is the spring ioc container. And the classic singleton's meaningful scope is the ClassLoader. You may find more about the distinction between these kinds of singleton here: A spring

How to change dependency registration at run time using simple injector?

风流意气都作罢 提交于 2019-12-07 07:57:13
问题 I'm using the Simple Injector IoC framework, and I would like to be able to change the dependency registration at run time. For example, I have two implementations, A and B , of interface I . Implementation A is registered at app start, but depending on some flag which can change during runtime, I would like to switch the implementation. We are currently doing this the OnActionExecuting event of our BaseController , which all of our controllers inherit from. Here is the sample code of what I

How to do a registration in Simple Injector after a GetInstance call / Alternate solution?

99封情书 提交于 2019-12-07 03:29:07
问题 Consider the following example: public class CommunicationClient : IClient { public CommunicationClient(IServerSettings settings) { ... } // Code } public class SettingsManager : ISettingsManager { SettingsManager(IDbSettingManager manager) // Code public IDictionary<string, string> GetSettings() { ... } } Problem : While performing registrations (using SimpleInjector ), I need to provide values that are obtained from an instance of SetingsManager and fill ServerSettings instance (concrete

How to use/configure Unity Container IOC in my situation

六眼飞鱼酱① 提交于 2019-12-07 03:08:27
I have some trouble implementing the Unity IOC into my project reading from config file. Here is what I have 1) ClasslibraryA 2) ClasslibraryB that references ClasslibraryA 3) Winforms App that references ClasslibraryB Note: SomeOther app will reference ClassLibraryA, eg. a web service. ClasslibraryA will have to be configured for IOC depending on where it is used. eg. IDataSource will be different if it is called in the web service and when it is called from a local app. ClasslibraryB will have its own set of dependencies as well to be injected by the main application, in this case, the