ninject

How can I implement Ninject .InSingletonScope() when using Unity IoC

浪子不回头ぞ 提交于 2019-12-06 11:20:05
问题 I was using ninject IoC in my application and in particular the following: kernel.Bind<RepositoryFactories>().To<RepositoryFactories>() .InSingletonScope(); I would like to implement this using the Unity IoC but can someone tell me how I can make it the same and also what does it mean "InSingletonScope()" ? The following works but I am worried that it's not being done correctly because of the Singleton that maybe needs to be specified. container.RegisterType<RepositoryFactories,

Is it a good practice to pass the Ninject kernel around?

北城以北 提交于 2019-12-06 11:00:02
I'm writing a small framework that executed a couple of tasks. Some om the tasks needs specific properties which are injected through Ninject. Let's say that I have the following constructor in my base class that represents a single Task: protected DDPSchedulerTask(ILogger logger, List<string> platforms, IBackOfficeDataStore backOfficeDataStore, ICommonDataStore commonDataStore) { _logger = logger; _platforms = platforms; _backOfficeDataStore = backOfficeDataStore; _commonDataStore = commonDataStore; } Those properties are needed for all the tasks, so I inject them using Ninject with the

How to Make Alternative Use of Interfaces for Wcf Contracts

≯℡__Kan透↙ 提交于 2019-12-06 09:53:20
问题 Lets say I have 3 assemblies, Example.Core, Example.Contracts, Example.WcfServices. In my contracts assembly I define an interface and add some operation, e.g. ICalculator, which has operation Add(double a, double b). In my WcfServices assembly I have an implementation of ICalculator explosed as a Wcf service. Now my question is this....in my Example.Core assembly how do I program against that interface while keeping everything decoupled (to allow me to have an alternative implementation of

How to pass parameters down the dependency chain using Ninject

半城伤御伤魂 提交于 2019-12-06 09:50:01
My Class Structure is: public class PhotoService { private IRepository _repo; private DTConfig _config; public PhotoService(IRepository repo, DTConfig config) { _repo = repo; _config = config; } } public class DTConfig { private int _accountId; public DTConfig(int accountId) { _accountId = accountId; } } My Ninject Bindings are like: var kernel = new StandardKernel(); kernel.Bind<IPhotoService>().To<PhotoService>(); kernel.Bind<IRepository>().To<Repository>(); kernel.Bind<DTConfig>().ToSelf(); Now what I want, is to pass the accountId as a parameter while creating an instance of PhotoService

Erro on Ninject: Sequence contains no elements

末鹿安然 提交于 2019-12-06 08:23:04
This error appear just when I publish on Azure server: Sequence contains no elements I'm not sure this error is because of Ninject. I've tried all the tips with similar errors, but it seems that is a generic error. I tried to run the same code on several machines and this error does not happen only when the public Azure. If you have gone through something and can help, thank you very much. Stack Trace : [InvalidOperationException: Sequence contains no elements] System.Linq.Enumerable.Single(IEnumerable`1 source) +311 Ninject.Web.Mvc.NinjectMvcHttpApplicationPlugin.Start() +44 Ninject.Web

Generic repository, DI, Aggregation Roots

落花浮王杯 提交于 2019-12-06 07:48:12
Having a generic repository like public class Repository<T> where T: Entity<T> { /*anything else*/ } should concrete repositories per agregation root like class ProductRepository : Repository<Product> { } class CategoryRepository : Repository<Category> { } be created? Also how do I use DI ( Ninject ) with generic implementation of repository. Samples are apreciated! Thanks! I see a lot of misuse of generics in the questions in SO and while it does not necessarily refer to your question (although it will help to clarify), I think once for all write a summary here. Generics is a typeless reuse

Ninject: Is it possible to have parent object in SingletonScope and child in TransientScope?

懵懂的女人 提交于 2019-12-06 07:32:32
问题 I have been racking my brain on and off with this for a few weeks now... What I currenlty have is this: A bunch of *Service classes All of these depend on different *Repository classes that access database via EF To allow Unit Testing a derivate of DbContext is injected into repositories. (so I can not use using to dispose of the contexts) To correctly dispose of the EF contexts that are injected I could run my dependency tree in InRequestScope() or in a simple custom scope - InScope(c => new

Membership reboot replace Ninject with Simple Injector

泪湿孤枕 提交于 2019-12-06 06:16:02
问题 I need add membership reboot (RavenDb) into the project that use IOC Simple Injector Ninject implementation var config = MembershipRebootConfig.Create(); kernel.Bind<MembershipRebootConfiguration<HierarchicalUserAccount>>().ToConstant(config); kernel.Bind<UserAccountService<HierarchicalUserAccount>>().ToSelf(); kernel.Bind<AuthenticationService<HierarchicalUserAccount().To<SamAuthenticationService<HierarchicalUserAccount>>(); kernel.Bind<IUserAccountRepository<HierarchicalUserAccount>>()

Anyone using Ninject 2.0 as the nServiceBus ObjectBuilder?

非 Y 不嫁゛ 提交于 2019-12-06 05:39:44
问题 I have been trying to get nServiceBus to work with Ninject 2.0 as the underlying IoC container unsuccessfully. While I can achieve basic integration, I've had issues with "ghost" messages getting sent to the various subscribers. I used the Autofac implementation as a template of sorts, replacing the necessary pieces with Ninject-specific code. Further, I did have to create a custom heuristic to get auto-property injection to occur. Regardless, the behavior I see is that a first message can be

NInject Extension Factory

我的梦境 提交于 2019-12-06 05:16:46
After reading the new documentation on NInject v3 and how to use the Factory Extension , apparently I still don't get it fully since my code throws exceptions all over the place... I get this Exception, i could paste the whole thing if people would like that but i'll try and keep it short for now. Error activating IDeployEntityContainer No matching bindings are available, and the type is not self-bindable. Here is my code... The Ninject Bind Module class class MyNinjectModule : NinjectModule { public override void Load() { ... Bind<IDeployEntityFactory>().ToFactory(); Bind