public SubObjectThree(IThirdService thirdService) { if (thirdService == null) { throw new ArgumentNullException("thirdService"); } }
public ActionResult Test() { IThirdService service = ThirdServiceContext.FindService("90335235-effd-44d8-927e-b17ccdde6844");//测试性能 service.DoService(null); return(null); }
public FirstService(ISecondService secondService, IThirdService thirdService) { _secondService = secondService; _secondService.SecondMethod(); _thirdService = thirdService; _thirdService.ThirdMethod(); }
public MultipleParameters(IFirstService firstService, ISecondService secondService, IThirdService thirdService, IFourthService fourthService) { _firstService = firstService; _secondService = secondService; _thirdService = thirdService; _fourthService = fourthService; }
//private static IThirdService CreateCastleProxy<T>() where T : IThirdService, new() //{ // ProxyGenerator generator = new ProxyGenerator(); // ThirdServiceInterceptor interceptor = new ThirdServiceInterceptor(); // T t = System.Activator.CreateInstance<T>(); // //IThirdService iservice = generator.CreateInterfaceProxyWithTargetInterface<IThirdService>(t, interceptor); // IThirdService iservice = generator.CreateInterfaceProxyWithTarget<IThirdService>(t,interceptor); // return iservice; //} private static IThirdService CreateProxy <T>(string id, StrObjectDict otherProperties) where T : IThirdService, new() { ProxyFactory factory = new ProxyFactory(); T t = System.Activator.CreateInstance <T>(); PropertyInfo p = t.GetType().GetProperty("OtherProperties"); p.SetValue(t, otherProperties, null); p = t.GetType().GetProperty("ID"); p.SetValue(t, id, null); ThirdServiceInterceptor interceptor = new ThirdServiceInterceptor(t); IThirdService proxy1 = factory.CreateProxy <IThirdService>(interceptor); return(proxy1); }
public WeatherForecastController(ILogger <WeatherForecastController> logger, IFirstService firstService, ISecondService secondService, IThirdService thirdService, IFifthService fifthService, ISeventhService seventhService, IServiceScopeFactory serviceScopeFactory) { _logger = logger; this._firstService = firstService; this._thirdService = thirdService; this._fifthService = fifthService; this._secondService = secondService; this._seventhService = seventhService; this._serviceScopeFactory = serviceScopeFactory; }
public Complex1( IFirstService firstService, ISecondService secondService, IThirdService thirdService, ISubObjectOne subObjectOne, ISubObjectTwo subObjectTwo, ISubObjectThree subObjectThree) { if (firstService == null) { throw new ArgumentNullException("firstService"); } if (secondService == null) { throw new ArgumentNullException("secondService"); } if (thirdService == null) { throw new ArgumentNullException("thirdService"); } if (subObjectOne == null) { throw new ArgumentNullException("subObjectOne"); } if (subObjectTwo == null) { throw new ArgumentNullException("subObjectTwo"); } if (subObjectThree == null) { throw new ArgumentNullException("subObjectThree"); } System.Threading.Interlocked.Increment(ref counter); }
public Complex2( IFirstService firstService, ISecondService secondService, IThirdService thirdService, ISubObjectOne subObjectOne, ISubObjectTwo subObjectTwo, ISubObjectThree subObjectThree) { if (firstService == null) { throw new ArgumentNullException("firstService"); } if (secondService == null) { throw new ArgumentNullException("secondService"); } if (thirdService == null) { throw new ArgumentNullException("thirdService"); } if (subObjectOne == null) { throw new ArgumentNullException("subObjectOne"); } if (subObjectTwo == null) { throw new ArgumentNullException("subObjectTwo"); } if (subObjectThree == null) { throw new ArgumentNullException("subObjectThree"); } System.Threading.Interlocked.Increment(ref counter); }
public Complex( IFirstService firstService, ISecondService secondService, IThirdService thirdService, ISubObjectOne subObjectOne, ISubObjectTwo subObjectTwo, ISubObjectThree subObjectThree) { if (firstService == null) { throw new ArgumentNullException("firstService"); } if (secondService == null) { throw new ArgumentNullException("secondService"); } if (thirdService == null) { throw new ArgumentNullException("thirdService"); } if (subObjectOne == null) { throw new ArgumentNullException("subObjectOne"); } if (subObjectTwo == null) { throw new ArgumentNullException("subObjectTwo"); } if (subObjectThree == null) { throw new ArgumentNullException("subObjectThree"); } Instances++; }
public Complex2( IFirstService firstService, ISecondService secondService, IThirdService thirdService, ISubObjectOne subObjectOne, ISubObjectTwo subObjectTwo, ISubObjectThree subObjectThree) { if (firstService == null) { throw new ArgumentNullException("firstService"); } if (secondService == null) { throw new ArgumentNullException("secondService"); } if (thirdService == null) { throw new ArgumentNullException("thirdService"); } if (subObjectOne == null) { throw new ArgumentNullException("subObjectOne"); } if (subObjectTwo == null) { throw new ArgumentNullException("subObjectTwo"); } if (subObjectThree == null) { throw new ArgumentNullException("subObjectThree"); } Instances++; }
public ServiceImplementation(IOtherService os, IThirdService ts) {
public ThirdServiceWrapper(IThirdService target) { this._target = target; }
public ThirdServiceInterceptor(IThirdService target) { this._target = target; }
public void ScopeTest() { var resolver = ObjectResolver.Create(); resolver.Register <IFirstService, FirstService>(Lifestyle.Singleton); resolver.Register <ISecondService, SecondService>(Lifestyle.Transient); resolver.Register <IThirdService, ThirdService>(Lifestyle.Scoped); resolver.Compile(); IThirdService sc1 = null; IThirdService sc2 = null; IThirdService sc3 = null; IThirdService sc4 = null; { using (var coResolver = resolver.BeginScope(ScopeProvider.Standard)) { var s1 = coResolver.Resolve <IFirstService>(); var s2 = coResolver.Resolve <IFirstService>(); var t1 = coResolver.Resolve <ISecondService>(); var t2 = coResolver.Resolve <ISecondService>(); sc1 = coResolver.Resolve <IThirdService>(); sc2 = coResolver.Resolve <IThirdService>(); Object.ReferenceEquals(s1, s2).IsTrue(); Object.ReferenceEquals(t1, t2).IsFalse(); Object.ReferenceEquals(sc1, sc2).IsTrue(); (sc1 as ThirdService).DisposeCount.Is(0); } (sc1 as ThirdService).DisposeCount.Is(1); sc1 = sc2 = sc3 = sc4 = null; } { using (var coResolver = resolver.BeginScope(ScopeProvider.ThreadLocal)) { var t1 = new Thread(_ => { sc1 = coResolver.Resolve <IThirdService>(); sc2 = coResolver.Resolve <IThirdService>(); }); t1.Start(); var t2 = new Thread(_ => { sc3 = coResolver.Resolve <IThirdService>(); sc4 = coResolver.Resolve <IThirdService>(); }); t2.Start(); t1.Join(); t2.Join(); Object.ReferenceEquals(sc1, sc2).IsTrue(); Object.ReferenceEquals(sc3, sc4).IsTrue(); Object.ReferenceEquals(sc1, sc3).IsFalse(); (sc1 as ThirdService).DisposeCount.Is(0); (sc3 as ThirdService).DisposeCount.Is(0); } (sc1 as ThirdService).DisposeCount.Is(1); (sc3 as ThirdService).DisposeCount.Is(1); sc1 = sc2 = sc3 = sc4 = null; } { using (var coResolver = resolver.BeginScope(ScopeProvider.AsyncLocal)) { Task.Run(async() => { sc1 = coResolver.Resolve <IThirdService>(); sc2 = await GetAsync(coResolver); }).Wait(); Task.Run(async() => { sc3 = await GetAsync(coResolver); sc4 = coResolver.Resolve <IThirdService>(); }).Wait(); Object.ReferenceEquals(sc1, sc2).IsTrue(); Object.ReferenceEquals(sc3, sc4).IsFalse(); (sc1 as ThirdService).DisposeCount.Is(0); (sc3 as ThirdService).DisposeCount.Is(0); } (sc1 as ThirdService).DisposeCount.Is(1); (sc3 as ThirdService).DisposeCount.Is(1); sc1 = sc2 = sc3 = sc4 = null; } }