ninject-conventions

Convention based binding of constructor string arguments with Ninject

谁都会走 提交于 2019-12-21 09:25:04
问题 I'm using Ninject as IoC container in my project. I have following class: public class SomeRepository:ISomeRepository { public SomeRepository(string someDatabaseConnectionString) { // some code here.. } } In my application settings file I have connection string named "someDatabase". By default the one should add following configuration in order to inject this connection string into the constructor: kernel.Bind<ISomeRepository>() .To<SomeRepository>() .WithConstructorArgument(

Ninject Conventions with Ninject Factory Extension To Bind Multiple Types To One Interface

霸气de小男生 提交于 2019-12-20 04:54:10
问题 I'm trying to expand on the scenario asked in the SO question titled Ninject Factory Extension Bind Multiple Concrete Types To One Interface by using Ninject Conventions for convention-based binding of the ICar implementations. I'm working off the accepted answer authored by Akim and his Gist outlining the full example. The difference is that I've replaced the explicit ICar bindings with convention-based bindings (or an attempt at it, at least ;) public class CarModule : NinjectModule {

Is there an OOB way in Ninject to configure service in singleton scope?

喜欢而已 提交于 2019-12-12 04:36:37
问题 I am using ninject with ninject.extenions.conventions . I would like to use a convention to initialize some services as singletons. I know it is straightforward to add a SingletonAttribute and use it with .WithAttribute<SingletonAttribute>() during configuration. But I don't want to reinvent the wheel. 回答1: There's no singleton attribute being deliver with Ninject or ninject conventions. The question is how you want to determine which types are bound .InSingletonScope() . Instead of an

Handling application settings with ninject and convention based binding

荒凉一梦 提交于 2019-12-11 06:24:03
问题 I am using Ninject in an MVC3 application and am trying to switch over to conventions based binding with ninject.extensions.conventions. Now let's say I have a class that needs access to application settings such as: public class Foo : IFoo { public Foo(string connectionString) { ... } } I think I understand how to do normal binding with Ninject like this: Bind<IFoo>() .To<Foo>() .WithConstructorArgument( "connectionString", ConfigurationManager.ConnectionStrings["Default"].ConnectionString);

Convention based binding of constructor string arguments with Ninject

十年热恋 提交于 2019-12-04 04:13:26
I'm using Ninject as IoC container in my project. I have following class: public class SomeRepository:ISomeRepository { public SomeRepository(string someDatabaseConnectionString) { // some code here.. } } In my application settings file I have connection string named "someDatabase". By default the one should add following configuration in order to inject this connection string into the constructor: kernel.Bind<ISomeRepository>() .To<SomeRepository>() .WithConstructorArgument("someDatabaseConnectionString", connString); But i want to implement conventional based binding of such strings. Values

Ninject Conventions with Ninject Factory Extension To Bind Multiple Types To One Interface

回眸只為那壹抹淺笑 提交于 2019-12-02 04:55:00
I'm trying to expand on the scenario asked in the SO question titled Ninject Factory Extension Bind Multiple Concrete Types To One Interface by using Ninject Conventions for convention-based binding of the ICar implementations. I'm working off the accepted answer authored by Akim and his Gist outlining the full example. The difference is that I've replaced the explicit ICar bindings with convention-based bindings (or an attempt at it, at least ;) public class CarModule : NinjectModule { public override void Load() { Bind<ICarFactory>() .ToFactory(() => new