I want to map DbConnection to an un-opened SqlConnection using Ninject. This is what I've done:
string constr = @"Server=.\SQLEXPRESS; Trusted_Connection=True; Database=TestDB";
Bind<DbConnection>().To<SqlConnection>()
.Using<OnePerRequestBehavior>()
.WithConstructorArgument("connectionString", constr);
However, when trying t...
I am going to use it in a project with less-experienced developers so a complex framework such as Spring.NET is not an option. I was thinking about:
Ninject
Castle Windsor
StructureMap
Which would present a moderate learning curve without losing flexibility?
and another question - where is the correct place to put the configuration?...
I have defined one interface and one class:
public interface IRepository<T>
{
}
public class RoleRepository:IRepository<Domain_RoleInfo>
{
}
Inject here:
public RoleService
{
[Inject]
public RoleService(IRepository<Domain_RoleInfo> rep)
{
_roleRep=rep;
}
}
How can I perform Dependency Injection With Ninject...
I was trying to inject an asp.net 2.0 good old web service reference but it failed. the failure was when trying to use the injected interface.
...
I decided to start using Ninject and face an issue. Say I have the following scenario.
I have an IService interface and 2 classes implementing this interface. And also I have a class, which has a constructor getting IService and an int. How can I create an instance of this class with Ninject (I dont want to hardwire this int, I want to p...
I have a class that has dependencies that I've wired up with Ninject.
public interface IFoo {}
public class MyObject {
[Inject]
IFoo myfoo;
}
In the real implementation I'm using property injection, but just to quickly illustrate, I'll inject on the field. As I understand, instead of newing instances of MyObject, in order ...
Hello,
i am using:-
asp.net mvc rc 2
Ninject and ninject asp.net mvc extension (http://github.com/enkari/ninject.web.mvc)
i keep getting the 'No parameterless constructor defined for this object.' for my AccountController. The AccountController is injected with Services. The bindings for these services are defined in the ServiceModu...
I have a method attribute which expects several properties to be injected by Ninject 2, but userSession and jobRepository are coming up as null:
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
public class JobAttribute : ActionFilterAttribute {
[Inject]
private IUserSession userSession;
[Inject]
private...
I am using .Net 3.5 and a console application that eventually will become a windows service.
Most of the examples I find use something like
Bind<IWeapon>().To<Sword>();
I have included all the DLL as references in my project and I the compiler is still complaining. Any clues of where I am going wrong? Sorry this might be a stupid qu...
I've started playing with Ninject and from a screencast it states the following is how you set up a binding:
class MyModule : StandardModule {
public override void Load() {
Bind<IInterface>().To<ConcreteType>();
// More bindings here...
}
}
This is all very good.
However suppose you have one hundred objects u...
Hi
I am hoping either Peter or Ruben sees this question as they seem to be the go to guys regarding Ninject. I needed to create a custom provider because I have a class that takes 4 arguments. The two can be injected because they are types but the other two are configuration parameters and are integers. They refer to timeouts in millise...
Hi, I am trying to use ninject with db4o and I have a problem. This is the relevant code from the Global.aspx
static IObjectServer _server;
protected override void OnApplicationStarted()
{
AutoMapperConfiguration.Configure();
RegisterRoutes(RouteTable.Routes);
RegisterAllControllersIn(Assembly.Get...
I'm using Ninject 1.0 and would like to be able to inject lazy initialisation delegates into constructors. So, given the generic delegate definition:
public delegate T LazyGet<T>();
I'd simply like to bind this to IKernel.Get() so that I can pass a lazy getter into constructors, e.g.
public class Foo
{
readonly LazyGet<Bar> getBa...
The officially released Ninject 2 no longer includes reference to the WebForms-specific functionality for IoC for WebForms, MasterPages, etc. It's now separated out into plugins/extensions; which in this case is the http://github.com/idavis/ninject.web extension. My problem however is that there's a dependency on log4net (or NLog) and I ...
Hi,
I am trying to use Ninject 2.0 with Asp .Net 3.5 web application. Following are the DLLS and it's versions I am using.
Ninject.dll - v2.0.0.0
Ninject.Extensions.Logging.dll v2.0.0.0
Ninject.Web.dll v1.0.0.0
In my global.ascx.cs I have following method.
protected override IKernel CreateKernel()
{
IKernel kernel = new...
I have an ASP.NET 3.5 WebForms application using Ninject 2.0. However, attempting to use the Ninject.Web extension to provide injection into System.Web.UI.Page, I'm getting a null reference to my injected dependency even though if I switch to using a service locator to provide the reference (using Ninject), there's no issue.
My configur...
I am open to other IoC containers, such as NInject and StructureMap if they are much cleaner than this. I hear that StructureMap just introduced "containers" that may simplify this , perhaps?
As the title says, is there a better way? This seems like a lot of code, just to register an object that requires a factory to create it.
// Th...
I have a class which is going to need to use the strategy design pattern. At run time I am required to switch different algorithms in and out to see the effects on the performance of the application.
The class in question currently takes four parameters in the constructor, each representing an algorithm.
How using Ninject (or a general...
Consider the following:
public Something(IInterface concreteObjectOne, IInterface concreteObjectTwo)
{
this.concreteObjectOne = concreteObjectOne;
this.concreteObjectTwo = concreteObjectTwo;
}
How do I set set this type of binding up with Ninject? I'd try Googling the term, but as I'm not sure what this is...
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-specif...