public static T Resolve <T>(this IObjectResolver resolver, IObjectObserver <T> observer)
        {
            var builder = observer.ObjectBuilder;

            if (builder == null)
            {
                throw new ObsoleteObjectBuilderException(GetObsoleteObjectBuilderErrorMessage(observer.ContractType));
            }
            return(resolver.Resolve(builder, null));
        }
 public static Exception TryResolve <T>(this IObjectResolver resolver, IObjectObserver <T> observer, out T instance)
 {
     try
     {
         instance = Resolve(resolver, observer);
         return(null);
     }
     catch (Exception ex)
     {
         instance = default(T);
         return(ex);
     }
 }
 public static Exception TryResolve(this IObjectResolver resolver, IObjectObserver observer, out object instance)
 {
     try
     {
         instance = Resolve(resolver, observer);
         return(null);
     }
     catch (Exception ex)
     {
         instance = null;
         return(ex);
     }
 }
示例#4
0
文件: Object.cs 项目: soulson/Drama
        public Task Unsubscribe(IObjectObserver observer)
        {
            VerifyExists();

            if (!observerManager.IsSubscribed(observer))
            {
                GetLogger().Warn($"observer {observer} tried to unsubscribe from {GetType().Name} {this.GetPrimaryKeyLong()} but was not subscribed");
            }
            else
            {
                observerManager.Unsubscribe(observer);
            }

            observer.HandleObjectDestroyed(State);

            return(Task.CompletedTask);
        }
        public bool TryGet <T>(Type contract, out IObjectObserver <T> observer)
        {
            Requires.NotNull(contract, "contract");
            ObjectBuilderGroup group;
            ObjectBuilder      builder;

            if (TryGetCore(contract, null, out group, out builder) != ObjectBuilderState.Normal)
            {
                observer = null;
                return(false);
            }
            var obs = new ObjectObserverImpl <T>(group, contract, builder.ToGeneric <T>());

            group.AddObserver(obs);
            observer = obs;
            return(true);
        }
示例#6
0
文件: Object.cs 项目: soulson/Drama
        public Task Subscribe(IObjectObserver observer)
        {
            VerifyExists();

            // TODO: determine how stealth/invisibility interact with this
            observer.HandleObjectCreate(State, GetCreationUpdate());

            if (observerManager.IsSubscribed(observer))
            {
                GetLogger().Warn($"observer {observer} tried to subscribe to {GetType().Name} {this.GetPrimaryKeyLong()} more than once");
            }
            else
            {
                observerManager.Subscribe(observer);
            }

            return(Task.CompletedTask);
        }
 public static bool TryGetObserver <T>(this IObjectResolver resolver, out IObjectObserver <T> observer)
 {
     return(resolver.Kernel.TryGet(typeof(T), out observer));
 }
 public static bool TryGetObserver(this IObjectResolver resolver, Type contractType, out IObjectObserver observer)
 {
     return(resolver.Kernel.TryGet(contractType, out observer));
 }
示例#9
0
 public bool TryGet <T>(Type contract, out IObjectObserver <T> observer)
 {
     return(_registry.TryGet(contract, out observer));
 }