ninject

ninject interceptor - helper methods

不打扰是莪最后的温柔 提交于 2019-12-12 05:28:04
问题 I have a simply interface: public interface ITest { void Method1(); void Method2(); } and implementation: public class Test:ITest { public void Method1() { } public void Method2() { //Method1(); } } The custom interceptor: public class CustomInterceptor:IInterceptor { public void Intercept(IInvocation invocation) { invocation.Proceed(); } } Now, when I execute there two methods: ITest obj = getting through ninject obj.Method1(); obj.Method2(); my interceptor is calling twice what is ok. But

How to make Ninject choose a specific constructor without using InjectAttribute?

佐手、 提交于 2019-12-12 05:15:57
问题 1) Is there a way to make Ninject select a specific constructor in code other than applying the InjectAttribute ? 2) Also, how do I supply values for these arguments of the constructor? 3) Can I override these argument values on resolution or creation of the object, i.e. when I call kernel.Get<T>() ? 回答1: There's the ToConstructor binding method: Bind<IMyService>().ToConstructor( ctorArg => new MyService(ctorArg.Inject<IFoo>())); You can specify values on binding using 3 mechanisms: create a

Ninject GetAll Where Module = foo

我的未来我决定 提交于 2019-12-12 04:47:24
问题 Is it possible to do something like this: var foos = Kernel.where(c=>c.module == myModule).GetAll<foo>; And how would one go about it? If(!possible) How can you discriminate between bindings to the same interface when using the GetAll() method? I am aware of WithParameter , WithMetadata , WithConstructorArgument and WithPropertyValue ; Which one should i use and why? Cheers More information I need this because I am creating a plugin framework. During the routing the plugin framework needs to

How do I let Ninject inject dependencies into my MVC controllers?

折月煮酒 提交于 2019-12-12 04:46:48
问题 How do you inject UserManager and UserStore into a controller? Ninject bindings are: kernel.Bind<ApplicationDbContext>().ToSelf().InRequestScope(); kernel.Bind(typeof(UserManager<>)).ToSelf().InRequestScope(); kernel.Bind(typeof(UserStore<>)).ToSelf().InRequestScope(); 回答1: To be able to auto-wire MVC controllers, you need to either replace MVC's default IControllerFactory or the default IDependencyResolver . There's a Ninject.MVC3 Nuget package that implements a dependency resolver for you.

Error: [ng:areq] http://errors.angularjs.org/1.3.8/ng/areq?p0=homeIndexController&p1=not a function, got undefined [duplicate]

巧了我就是萌 提交于 2019-12-12 04:45:18
问题 This question already has answers here : Controller not a function, got undefined, while defining controllers globally (14 answers) Closed 4 years ago . Please do not mark this as a duplicate. I have seen many duplicates of this error posted in stack overflow. But my case is, I have the simplest of the applications posted there, but getting the same error. I am trying to learn Angular JS. Below is my _Layout.chtml looks like. <!DOCTYPE html> <html lang="en" data-ng-app=""> <head> <meta

Unity get Type of the service where the dependecy gets injected

旧时模样 提交于 2019-12-12 04:44:45
问题 Is it possible to get, in Unity, the Type of the service where the dependecy gets injected? In Ninject you can do it like this: kernel.Bind<ILogger>().ToMethod((context) => { ILogger logger = HttpContextLoggerFactory.GetInstance(); // Eg: MyApplication.PeopleRepository string memberType = context?.Request?.Target?.Member?.DeclaringType?.FullName; return new LoggerMemberTypeDecorator(logger, memberType); }); How can the same thing be implemented in Unity ? Here is what i have, but i do not

EF4.0 - Is there a way to see what entities are attached to what ObjectContext during debugging?

☆樱花仙子☆ 提交于 2019-12-12 04:38:39
问题 This is in continuation with my problem here. I'm trying to use the solution Julie Lerman gave me a few months ago. I'm currently using the following to generate a new Game entity pre-attached to my ObjectContext: Game game = _gameRepository.GetGame(formData.GameID); AutoMapper.Mapper.Map<AdminGameEditModel, Game>(formData, game); In the repository, I try to attach the Game to the OC with its state set to 'Added' like she suggested by doing the following: public Game GetGame(int id) { if (id

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

Ninject - Binding a tree of data

六月ゝ 毕业季﹏ 提交于 2019-12-12 04:31:31
问题 I had recently the opportunity to get started with Ninject and more generally with IOC. I came across a specific problem that is taking me quite some time to resolve. I have a class A that contain childrens of the same class and a parent. class ClassA : IClassA { ICollection<IClassA> childrens; IClassA parent; } Specific instance of this class will be instanciated and I want to use Ninject to define my bindings, so that when calling for a specific instance of A, the right childrens and parent

Getting the request body of search response with 2.X NEST client

纵然是瞬间 提交于 2019-12-12 04:24:14
问题 I'm using the new 2.X NEST client. That part is important, because there were a great many breaking changes which will effect potential answers here. Previously, I used the Glimpse Elasticsearch plugin to see the underlying queries being generated by NEST. However, it would appear that that plugin is no longer compatible with 2.X NEST. As a result, I'm trying to find a workaround to see the JSON query. The problem here is that the old way of accessing response.RequestInformation to get at the