ninject

nservicebus saga property injection with ninject

孤人 提交于 2019-12-12 03:12:29
问题 I am using ninject when configuring NSB. Here is how I register: public class EndpointConfig : IConfigureThisEndpoint, AsA_Publisher, IWantCustomInitialization { #region Implementation of IWantCustomInitialization public void Init() { var kernel = new StandardKernel(); Configure.With().NinjectBuilder(kernel); kernel.Load(new BackendModule()); } #endregion } public class BackendModule : NinjectModule { #region Overrides of NinjectModule /// <summary> /// Loads the module into the kernel. /// <

Ninject + NHibernate with two or more databases

痞子三分冷 提交于 2019-12-12 03:08:29
问题 I have declared my Ninject bindings in a NinjectModule like this: public override void Load() { Bind<ISessionFactory>().ToMethod(c => SessionFactory1.SessionFactory).InSingletonScope().Named("d1"); Bind<ISessionFactory>().ToMethod(c => SessionFactory2.SessionFactory).InSingletonScope().Named("d2"); Bind<ISession>().ToMethod(c => c.Kernel.Get<ISessionFactory>("d1").OpenSession()).Named("d1"); Bind<ISession>().ToMethod(c => c.Kernel.Get<ISessionFactory>("d2").OpenSession()).Named("d2"); Bind

Ninject - Setting dependencies constructor with run-time value

╄→гoц情女王★ 提交于 2019-12-12 02:46:19
问题 I'm fairly new to DI/Ninject and I can't seem to figure out what I need to do. I have a service like this: public class ArchiveService : IArchiveService { private string sAuditUser = "USER"; public ArchiveService(string AuditUser) { sAuditUser = AuditUser; } ... } I'm currently instantiated the service like this: string sUser = HttpContext.Session["UID"].ToString(); ArchiveService svcArchive = new ArchiveService(Session["UID"].ToString()); The session value gets set when a user successfully

ASP.NET MVC 2 route errors - problems when using cottsak's solution

谁说我不能喝 提交于 2019-12-12 01:58:41
问题 I figured it'd be easier to ask here, where I can post some code, than in the comments of his solution. To see his solution, go here. EDIT: Some progress, but a new error. In my ErrorController class, I'm getting a NotImplementedException: public ActionResult InvokeHttp404(HttpContextBase httpContext) { IKernel kernal = new StandardKernel(); IController errorController = kernal.Get<ErrorController>(); var errorRoute = new RouteData(); errorRoute.Values.Add("controller", "Error"); errorRoute

NInject Custom context

旧街凉风 提交于 2019-12-12 01:57:53
问题 I'll expose what I'm doing now, and later, what I'd like to do using NInject. Classes: Kernel, ApiClient IIdentity Kernel exposes several methods as: object method(IIdentity identity) ----------------------- public List<Domain.Channel> getChannels(Domain.Identity.IIdentity identity) {...} Kernel contains several identities stored, and according each context I need to do a thing or another. In this case, my context is inside the method and the context key is identity parameter value. According

Declare a new log4net logger using Ninject

放肆的年华 提交于 2019-12-12 01:56:53
问题 I'm developing a Web Api application with C#, .NET Framework 4.0, Ninject 3.2.2.0 and log4net 2.0.3. Now, I only using one logger. This is how I configure if on NinjectConfigurator class. private void ConfigureLog4net(IKernel container) { log4net.Config.XmlConfigurator.Configure(); var loggerForWebSite = LogManager.GetLogger("AutomationMiddlewareWebsite"); container.Bind<ILog>().ToConstant(loggerForWebSite); } But, I need to use another logger. Using, Ninject, how can I do it? I'm don't know

How to solve Cyclic Dependency

一笑奈何 提交于 2019-12-12 00:05:53
问题 public class NotificationService: INotificationService{ private ILogService _logService; public NotificationService(ILogService logService){ _logService = logService; } } public class LogService: ILogService{ private INotificationService _notificationService; public LogService(INotificationService notificationService){ _notificationService = notificationService; } } I came into a situation where two classes depends on each other. I am using Ninject. Bind<INotificationService>().To

Can I specify multiple parameters using WhenInjectedInto for ninject?

大城市里の小女人 提交于 2019-12-11 23:34:30
问题 When setting up my ninject bindings, I'm using the .ToMethod to specify particular parameters for specific connectionstrings, and the WhenInjectedInto method to constrain the binding to specific types: Bind(Of IDbConnection).ToMethod(Function(context) New OracleConnection(ConnectionStringFactory.GetConnection(DBC.ConnectionStrings.Oracle))).WhenInjectedInto(Of AccountBalancesLookup)() Bind(Of IDbConnection).ToMethod(Function(context) New OracleConnection(ConnectionStringFactory.GetConnection

Initialising configurable objects with dependency injection container

会有一股神秘感。 提交于 2019-12-11 23:23:25
问题 I am trying to find the best way to initialise device drivers (maintained by production staff). Configuration generally contains serial ports and other information which production staff may need to change if the underlying hardware for the device driver changes. e.g. using System.IO.Ports; public class Scanner : IDriver { public SerialPort SerialPort { get; private set; } public String Id { get; private set; } public String DisplayName { get; private set; } public Scanner(SerialPort

How do I bind a class which takes its parent class in the constructor with Ninject?

北慕城南 提交于 2019-12-11 21:45:10
问题 I have a class like this: public class MyClass { public MyClass() { this.Dependency = new Dependency(this); } } I want to move the new Dependency() call to the constructor. public class MyClass { public MyClass(IDependency dependency) { this.Dependency = dependency; } } I can't work out how to bind it so that the IDependency is created with the 'this' constructor argument. Bind<IDependency>() .To<Dependency>() .WithConstructorArgument("myClass", ctx => ctx.???); // How do I do this? 回答1: The