Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not sure why this is failing ... #36

Closed
ghost opened this issue Feb 24, 2017 · 5 comments
Closed

Not sure why this is failing ... #36

ghost opened this issue Feb 24, 2017 · 5 comments

Comments

@ghost
Copy link

ghost commented Feb 24, 2017

Tried:

Implementing Ninject.Extensions.Interception.IInterceptor, easy enough called 'InstrumentationInterceptor'.

public class InstrumentationInterceptor : IInterceptor
	{
		private static readonly ILog Log;

		static InstrumentationInterceptor()
		{
			Log = new RepositoryLoggingService().GetLogger(typeof(InstrumentationInterceptor));
		}

		private T TimeWrap<T>(string message, Func<T> function)
		{
			var stopWatch = Stopwatch.StartNew();

			var result = function();

			stopWatch.Stop();

			Log.Info($"{message}::{stopWatch.ElapsedMilliseconds}ms");

			return result;
		}

		public void Intercept(IInvocation invocation)
		{
			var message = $"Connect.Repository.Instrumentation -> {MethodSignatureFormatter.GetSignature(invocation.Request.Method, invocation.Request.Arguments)}";

			TimeWrap(message, () =>
			{
				invocation.Proceed();

				return invocation.ReturnValue;
			});
		}
	}

Then registering with:

Kernel.Bind<InstrumentationInterceptor>().ToSelf().InSingletonScope();

 Kernel.Bind(x => x
                .From(GetType().Assembly)
                .SelectAllClasses()
                .InNamespaceOf(GetType())
                .BindAllInterfaces()
				.Configure(c => c.Intercept(
					typeof(InstrumentationInterceptor),
					typeof(DatabaseWinsConcurrencyInterceptor))));


Ended up with:

[NullReferenceException]: Object reference not set to an instance of an object.
at Ninject.Extensions.Interception.Advice.Advice.GetInterceptor(IProxyRequest request)
at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at Ninject.Extensions.Interception.Registry.AdviceRegistry.GetInterceptorsForRequest(IProxyRequest request)
at Ninject.Extensions.Interception.Registry.AdviceRegistry.GetInterceptors(IProxyRequest request)
at Ninject.Extensions.Interception.Wrapper.StandardWrapper.CreateInvocation(IProxyRequest request)
at Ninject.Extensions.Interception.Wrapper.DynamicProxyWrapper.Intercept(IInvocation castleInvocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.IAuthenticationRepositoryProxy.FindUser(String userName, String password)

@ghost
Copy link
Author

ghost commented Feb 24, 2017

Any idea's?

@ghost
Copy link
Author

ghost commented Sep 18, 2017

Closing this for now. Thanks.

@ghost ghost closed this as completed Sep 18, 2017
@scott-xu
Copy link
Member

scott-xu commented Sep 19, 2017

You missed With function after Intercept

@scott-xu
Copy link
Member

The syntax is "intercept some types with some interceptors"

@ghost
Copy link
Author

ghost commented Sep 19, 2017

@scott-xu - thanks, this really was not obvious.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant