ninject-2

Getting SNAP(AOP), NInject and ASP.Net MVC 3 working together

荒凉一梦 提交于 2019-12-05 10:35:51
问题 Has anyone got the SNAP AOP framework working with MVC 3 and Ninject. The samples given when adding Snap using NuGet to an MVC 3 project don't specifcally work well with a previously added NInject package. I have tried to get it working based on the normal NInject approach but just cannot get it to actually intercept! Can anyone show how to do this in code please? 回答1: I figured it out with the latest version of Ninject through NuGet which now adds a class call NinjectMVC3 in a new AppStart

Ninject, passing constructor argument to the kernel

让人想犯罪 __ 提交于 2019-12-05 04:01:33
Here is my problem: I want to pass in one of the values to the constructor every time I request an instance form the kernel. I written some code below to illustrate the problem. The test is not failing so I guess that this works, but it does look pretty ugly. Is there a better, cleaner way to accomplish this with Ninject? Or should I rethink my design? All suggestions are appreciated. [TestFixture] public class Sandbox { [Test] public void Run_Forrest_Run() { using (var kernel = new StandardKernel(new Module())) { var connection = new Connection(Guid.NewGuid().ToString()); var downloader =

Ninject InRequestScope missing

百般思念 提交于 2019-12-04 22:14:24
Have a couple of questions regarding the latest version (2.2.1.4) of ninject. Was trying to Bind a Linq2sql DataContext to a concrete implementation InRequestScope (in a class library project) Bind<DataContext>().To<MoneywatchDataContext>() but could not find InRequestScope method ended up doing this, Bind<DataContext>().To<MoneywatchDataContext>().InScope(ctx => HttpContext.Current) Just wanted to find out if: If this will behave exactly like the InRequestScope Method. That it will gurantee that when my HTTContext.Current is GC'ed the underlying DataCotext will be disposed as well. Remo Gloor

Ninject.MockingKernel.Moq security exception

半腔热情 提交于 2019-12-04 16:48:02
I am using Ninject for my IoC container and I'm trying to write some unit tests. I found the Ninject Mocking Kernel so I thought I'd give it a go but I can't get the simplest test to pass. I am missing something and need a little help. Moq.4.0.10827.Final Ninject-2.2.0.0-release-net-4.0 Ninject.MockingKernel-2.2.0.0-release-net-4.0 My unit test... [TestMethod] public void Constructor_CanInitialize() { var kernel = new MoqMockingKernel(); var mock = kernel.Get<IDataRepository>(); <--Error here Assert.IsInstanceOfType(mock, typeof(DataRepository)); } Here is the error... Test method TestFixture

Ninject WithConstructorArgument : No matching bindings are available, and the type is not self-bindable

瘦欲@ 提交于 2019-12-04 15:47:05
问题 My understanding of WithConstructorArgument is probably erroneous, because the following is not working: I have a service, lets call it MyService, whose constructor is taking multiple objects, and a string parameter called testEmail. For this string parameter, I added the following Ninject binding: string testEmail = "test@example.com"; kernel.Bind<IMyService>().To<MyService>().WithConstructorArgument("testEmail", testEmail); However, when executing the following line of code, I get an

Ninject 2.2 multiple bindings

£可爱£侵袭症+ 提交于 2019-12-04 14:57:51
I recently updated ASP.NET MVC 3 app to Ninject 2.2. Previously I had the following interface to implementation binding in my main app: Bind(typeof(IMyInterface<>)).To(typeof(MyImplementation<>)).InRequestScope(); In addition, I had the following in a different assembly that was being loaded by my main app: var arg = new ConstructorArgument("info", "something"); Bind<IMyInterface<MyClass>>().To<MyImplementation<BlogComment>>().WithParameter(arg); This worked fine previously and the more specific implementation (the one with the argument) was being recognized. However, when I upgraded to

ASP.NET MVC 3 and Global Filter Injection

二次信任 提交于 2019-12-04 13:43:42
问题 Hello am an trying to implement a global filter with injection. The filter looks like this. public class WikiFilter : IActionFilter { private IWikiService service; public WikiFilter(IWikiService service) { this.service = service; } public void OnActionExecuting(ActionExecutingContext filterContext) { !!!Code here!! } public void OnActionExecuted(ActionExecutedContext filterContext) { throw new NotImplementedException(); } } And i have attached the filter with injection the following way in my

Property Injection in Base Controller using Ninject 2

假装没事ソ 提交于 2019-12-04 08:52:38
I have the following code in my Global.aspx protected override void OnApplicationStarted() { AreaRegistration.RegisterAllAreas(); RegisterRoutes(RouteTable.Routes); RegisterAllControllersIn(Assembly.GetExecutingAssembly()); } protected override IKernel CreateKernel() { return new StandardKernel(new ServiceModule()); } I also have the following Ninject Module: internal class ServiceModule : NinjectModule { public override void Load() { Bind<IProductService>().To<ProductService>().InRequestScope(); } } I also have a base controller: public class BaseController : Controller { [Inject] public

Ninject, Bind should be .InRequestScope() OR .InSingletonScope()

不羁岁月 提交于 2019-12-03 17:17:47
问题 I have Below code One is bindable to my User Repository and another for Cache. What scope should I use for UserRepository and Cache. Should Scope on UserRepository be Singleton? this.Bind<IUserRepository>().To<UserRepositary>().InRequestScope(); this.Bind<IDistributedCacheService>().To<DistributedCacheService>().InSingletonScope(); 回答1: Usually the repositories are bound inrequestscope because that generally defines the unit of work or database transaction size. Update: Here is a bit more

Ninject.Extensions.Logging.Log4net unexpected behavior

别来无恙 提交于 2019-12-03 14:16:32
I am having a problem using Log4Net (1.2.10) through Ninject's (2.2.1.4) Extensions.Logging.Log4net (2.2.0.4), as installed through NuGet. When I access Log4Net directly: var logger = log4net.LogManager.GetLogger("Log4NetLoggerTest"); logger.Debug("foo { bar"); The result is: 2011-08-29 10:02:02,071 [9] DEBUG Log4NetLoggerTest foo { bar However, when the logger is accessed through Ninject: using (IKernel kernel = new StandardKernel()) { var ninjectLogger = kernel.Get<NinjectLoggerTest>(); ninjectLogger.Log.Debug("foo { bar"); } Where NinjectLoggerTest is simply this: using Ninject.Extensions