// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Concurrent;
using Autofac;
using Autofac.Core;
namespace MvcSample.Web
{
///
/// Summary description for MonitoringModule
///
public class MonitoringModule : Module
{
private static ConcurrentDictionary, int> _registrations
= new ConcurrentDictionary, int>();
private static ConcurrentDictionary, object> _instances
= new ConcurrentDictionary, object>();
public static readonly ConcurrentDictionary, int> InstanceCount
= new ConcurrentDictionary, int>();
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry,
IComponentRegistration registration)
{
registration.Activating += Registration_Activating;
registration.Activated += Registration_Activated;
}
public Tuple GetKey(IComponentRegistration context)
{
var activator = context.Activator;
var lifeTime = context.Lifetime;
var limitType = context.Activator.LimitType;
var key = new Tuple(limitType, lifeTime);
return key;
}
private void Registration_Activated(object sender, ActivatedEventArgs