I am going to track all the activities that occurred on services that are managed by the Unity container like logs on the file system. I suppose I could define an interface called IService, and all other interfaces or implementation should inherit it. On the other hand, I would like to develop a custom interception behavior or call handler to save logs to files.
Unfortunately, I found that this does not work for me using these codes.
IUnityContainer unity = new UnityContainer(); //Interception unity.AddNewExtension<Interception>(); Interception interception = unity.Configure<Interception>(); unity.RegisterType<IService>( new DefaultInterceptor(new InterfaceInterceptor()), new DefaultInterceptionBehavior(new LoggingBehavior())); string[] configFiles = Directory.GetFiles(".", "*.config"); foreach (string configFile in configFiles) { var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = configFile }; System.Configuration.Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None); var unitySection = (UnityConfigurationSection) configuration.GetSection("unity"); unity = unitySection.Configure(unity); } IGateway imapGW = unity.Resolve<IGateway>("ImapGateway");
Do I have a misunderstanding using interceptor in Unity? How can I deal with this problem to record everything automatically without setting up an interceptor for each service?
source share