私はLightProjectをMVC Webサイト上のServiceProviderアダプタとともに使用しています。私はMiniProfilerに配線しようとしていますが、私は大したことはありません。 MiniProfilerは、依存関係のいずれかのMVCコントローラのライフサイクルを捕捉し、ではなくているように見える: Mini Profiler Image Profiling Dump (I was debugging during this screenshot - ignore the 61,744 ms duration)LightInject - インターセプト依存関係を傍受しない
これは私がコンテナを初期化しています方法です:
protected override IServiceProvider BuildServiceProvider(IServiceCollection serviceCollection)
{
var container = new ServiceContainer();
container.Register<IInterceptor, MiniProfilerInterceptor>();
foreach (var descriptor in serviceCollection)
{
if (descriptor.ServiceType.AssemblyQualifiedName.StartsWith("ProjectName"))
{
container.Intercept(s => s.ServiceType == descriptor.ServiceType, i => i.GetInstance<IInterceptor>());
}
}
var serviceProvider = container.CreateServiceProvider(serviceCollection);
return serviceProvider;
}
インターセプタは、次のようになります。
public class MiniProfilerInterceptor : IInterceptor
{
public object Invoke(IInvocationInfo invocation)
{
var profiler = MiniProfiler.Current;
var returnType = invocation.Method.ReturnType;
using (profiler.Step(invocation.Proxy.GetType().Name + ":" + invocation.Method.Name))
{
return invocation.Proceed();
}
}
}
これは、コントローラと、試験依存性である:
public class SomeDependencyController : Controller
{
private readonly SomeDependency _dependency;
public SomeDependencyController(SomeDependency dependency)
{
_dependency = dependency;
}
public MvcHtmlString DoSomething()
{
_dependency.DoSomething();
return new MvcHtmlString("Did it");
}
public ActionResult DoRender()
{
_dependency.DoSomething();
return View("DoRender");
}
}
public class SomeDependency
{
public void DoSomething()
{
Thread.Sleep(1000);
}
}
私はインターセプタコードにブレークポイントを投げました。それはSomeDependency
のためのもののためにインターセプタに入ることはありませんが、SomeDependencyController