public interface ISecond { } public class Second : ISecond { } public interface IExample { } public class Example : IExample { public Example(ISecond second) { } }
Test 1
1 2 3 4 5
Stopwatch s = new Stopwatch(); s.Start(); Locator.CurrentMutable.RegisterLazySingleton(() => new Second(), typeof(ISecond)); Locator.CurrentMutable.RegisterLazySingleton(() => new Example(Locator.Current.GetService<ISecond>()), typeof(IExample)); s.Stop();
Test 2
1 2 3 4
Stopwatch s = new Stopwatch(); s.Start(); Locator.Current.GetService<ISecond>(); s.Stop();
Test 3
1 2 3 4
Stopwatch s = new Stopwatch(); s.Start(); Locator.Current.GetService<IExample>(); s.Stop();
近期评论