The name 'Bind' does not exist in the current context

401 views
Skip to first unread message

Adrian Grigore

unread,
Jul 4, 2009, 7:16:18 AM7/4/09
to ninject
Hi,

Ninject looks great, so I'd like to use it in my project.
Unfortunately I am still struggling to do the most trivial binding.
The [Inject] attribute compiles just fine, but the compiler cannot
find the "Bind" command:

using System;
using Ninject.Core;
using Ninject.Core.Binding;

namespace NinjectTest
{
public interface IFoo
{
void DoSomething();
}

public class Foo : IFoo
{
public void DoSomething()
{
throw new NotImplementedException();
}
}

public class Bar
{
[Inject] private IFoo theFoo;

public Bar()
{
Bind<IFoo>().To<Foo>(); //Compiler Error: "The name 'Bind'
does not exist in the current context"
}
}
}

What could be going wrong here?

Thanks,

Adrian

Adrian Grigore

unread,
Jul 4, 2009, 10:13:43 AM7/4/09
to ninject
I managed to get my application to compile by deriving from
StandardModule. However, how I get a NullReferenceException when Bind
is being called. Here's the call stack:

Ninject.Core.ModuleBase`1.get_Logger() in d:\Projects\Ninject\src\Core
\Modules\ModuleBase.cs:64
Ninject.Core.ModuleBase`1.DoBind(Type type) in d:\Projects\Ninject
\src\Core\Modules\ModuleBase.cs
:262
Ninject.Core.ModuleBase`1.Bind() in d:\Projects\Ninject\src\Core
\Modules\ModuleBase.cs:116
Zeiterfassung.Controllers.Ninjector.Load() in H:\Projects
\Zeiterfassung\Controllers\ControllerBase.cs:23


I'm sure this is just another trivial problem and I'd love to solve it
myself by RTFM, but the documentation is of very little help here (as
in the previous problem I described) and the tests from the Ninject
source are too complex for me to figure out what's going wrong in my
project. Is there perhaps a simplistic demo project that shows Ninject
in action? That would probably be the fastest way to get Ninject
beginners like me up and running.

Thanks,

Adrian

Ian Davis

unread,
Jul 4, 2009, 10:38:43 AM7/4/09
to nin...@googlegroups.com
There are blog posts and tutorials. The unit tests are also a good way to see how things work. It looks like you are trying to inject a logger. Make sure that you load the Log4netModule or NLogModule
--
Ian Davis

Adrian Grigore

unread,
Jul 4, 2009, 12:07:38 PM7/4/09
to ninject
Thanks for your reply. I finally managed to successfully add Ninject
after reading this blog article:
http://codeclimber.net.nz/archive/2009/02/05/how-to-use-ninject-with-asp.net-mvc.aspx#ninject-download

Reply all
Reply to author
Forward
0 new messages