static CacheAttribute()
 {
     // Use AspectServiceLocator to initialize the cache service field at application run-time.
     if (!PostSharpEnvironment.IsPostSharpRunning)
     {
         cache = AspectServiceLocator.GetService <IMemoryCache>();
     }
 }
    public static void Main(string[] args)
    {
        IWebHost host = CreateWebHostBuilder(args).Build();

        // Initialize the AspectServiceLocator during ASP.NET Core program start-up
        AspectServiceLocator.Initialize(host);
        host.Run();
    }
        public void TestMethod()
        {
            // The ServiceLocator can be initialized for each test.
            AspectServiceLocator.Initialize(new TypeCatalog(typeof(TestLogger)), false);

            TestLogger.Clear();
            TargetMethod();
            Assert.AreEqual("OnEntry" + Environment.NewLine, TestLogger.GetLog());
        }
 public void TestMethod()
 {
     // The ServiceLocator can be initialized for each test.
     using (
         AspectServiceLocator.AddRule <ILogger>(
             (type, member) =>
             type == typeof(LogAspect) && member.Name == "TargetMethod" ? new TestLogger() : null)
         )
     {
         TestLogger.Clear();
         TargetMethod();
         Assert.AreEqual("OnEntry" + Environment.NewLine, TestLogger.GetLog());
     }
 }
Esempio n. 5
0
 static TestLogAspect()
 {
     AspectServiceLocator.Initialize(new TypeCatalog(typeof(TestLogger)));
 }