ioc-container

Ninject and DataContext disposal

为君一笑 提交于 2019-12-21 06:55:13
问题 I'm using Ninject to retrieve my DataContext from the kernel and I was wondering if Ninject automatically disposes the DataContext, or how he handles the dispose() behaviour. From own experiences I know disposing the datacontext is pretty important and that whenever you create a direct object of the DataContext (as in: new DataContext()) you should use a using() block. My question thus is: When im retrieving my DataContext from the kernel, should I still have to use a using() block? Or does

Ninject and DataContext disposal

℡╲_俬逩灬. 提交于 2019-12-21 06:53:18
问题 I'm using Ninject to retrieve my DataContext from the kernel and I was wondering if Ninject automatically disposes the DataContext, or how he handles the dispose() behaviour. From own experiences I know disposing the datacontext is pretty important and that whenever you create a direct object of the DataContext (as in: new DataContext()) you should use a using() block. My question thus is: When im retrieving my DataContext from the kernel, should I still have to use a using() block? Or does

How to Avoid Coupling with an IoC Container

二次信任 提交于 2019-12-21 05:03:29
问题 I'm in the process of developing an extensible framework using DI and IoC. Users must be able override existing functionality within the framework by dropping their own implementations into the container. How can I allow users to do this without requiring them to know which IoC container I am using? My current half-way solution is to structure my assemblies as follows: 1) Define abstract assemblies containing only interfaces. 2) Define concrete assemblies which implement these interfaces.

Use autofac in multiple project solution

我与影子孤独终老i 提交于 2019-12-21 04:51:40
问题 I have large wpf application. I simplify my problem with autofac. Let say I have ViewModelLocator where I create contrainer. ViewModelLocator is in Company.WPF project, this project refers Company.ViewModels project. var builder = new ContainerBuilder(); builder.RegisterType<MainWindowViewModel>().AsSelf().SingleInstance(); container = builder.Build(); Problem: MainWindowViewModel needs ICompanyService (I use CI) which is in Company.Services project, this project should not be reference from

Spring ordered list of beans

五迷三道 提交于 2019-12-21 03:42:23
问题 I have several beans that implement the same interface. Each bean is annotated with @Component @Order(SORT_ORDER). public class MyClass implements BeanInterface{ ... } At one point I autowire a list of components and I expect a sorted list of beans. The list of beans is not sorted according the orders I have set with the annotation. I tried implementing the interface Ordered and the same behaviour occurs. @Component public class Factory{ @Autowired private List<BeanInterface> list; // <- I

When to use an IOC container?

巧了我就是萌 提交于 2019-12-20 10:29:23
问题 I'm trying to understand when I should use a container versus manually injecting dependencies. If I have an application that uses a 1-2 interfaces and only has 1-2 concrete implementations for each interface, I would lean towards just handling that myself. If I have a small application that uses 2-3 interfaces and each interface has 2-3 concrete implementations, should I use a full-blown container? Would something something simple like this suffice? Basically I'm trying to understand when it

Resolve instance with multiple constructors using unity

白昼怎懂夜的黑 提交于 2019-12-20 10:27:21
问题 I'd like to create an instance of a class using unity where the class has two constructors with the same number of parameters. Here is the instantiation: _unityContainer.Resolve<IGradeType>(new ParameterOverride("gradeTypeStringFromXmlFile", gradeTypeStringFromXmlFile)); And here are the constructors: public GradeType(string gradeTypeStringFromXmlFile) { _gradeTypeStringFromXmlFile = gradeTypeStringFromXmlFile; } public GradeType(Enum.GradeType gradeType) { _gradeType = gradeType; } If I try

Should Unity be configured in code or configuration file?

走远了吗. 提交于 2019-12-20 09:37:39
问题 Microsoft's Unity dependency injection framework can be configured either through code or through the applications configuration file (app.config). Code example: IUnityContainer container = new UnityContainer() .RegisterType<IInterface, ConcreteImplementation>(); Configuration example: <unity> <containers> <container> <types> <type type="IInterface, MyAssembly" mapTo="ConcreteImplementation, MyAssembly" /> What are the advantages/disadvantages to each approach? I can think of the obvious

Autofac DbContext has been disposed

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-20 06:29:06
问题 I've read this post DbContext has been disposed and autofac but I'm still getting the same error: The operation cannot be completed because the DbContext has been disposed. public class EFRepository : IRepository { private EFDbContext context; public EFRepository(EFDbContext ctx) { context = ctx; } public TEntity FirstOrDefault<TEntity>(Expression<Func<TEntity, bool>> predicate, params Expression<Func<TEntity, object>>[] includes) where TEntity : class, IContextEntity { IQueryable<TEntity>

What is self-binding in an IoC container?

一世执手 提交于 2019-12-20 03:31:22
问题 I've seen frameworks like Ninject as well as posts on Stack speak about self binding when using dependency injection frameworks like in the code below. Bind<Samurai>().To<Samurai>(); They even go to the extent of having special syntax for this: Bind<Samurai>().ToSelf(); Why would you want to bind a type to itself? I don't see any practical applications for where this might be useful and help reduce dependencies in code. Wouldn't this just mean a reference to a type would simply resolve to