Inheritance: MemoryContext, IFrozenContext
コード例 #1
0
ファイル: MemoryProvider.cs プロジェクト: jrgcubano/zetbox
        protected override void Load(ContainerBuilder moduleBuilder)
        {
            base.Load(moduleBuilder);

            moduleBuilder
                .RegisterType<MemoryImplementationType>()
                .As<MemoryImplementationType>()
                .As<ImplementationType>()
                .InstancePerDependency();

            moduleBuilder
                .RegisterType<MemoryContext>()
                .As<BaseMemoryContext>()
                .OnActivated(args =>
                {
                    var manager = args.Context.Resolve<IMemoryActionsManager>();
                    manager.Init(args.Context.Resolve<IFrozenContext>());
                })
                .InstancePerDependency();

            try
            {
                // TODO: Move to MemoryModule
                var generatedAssembly = Assembly.Load(GeneratedAssemblyName);
                moduleBuilder
                    .Register(c =>
                    {
                        FrozenMemoryContext memCtx = null;
                        memCtx = new FrozenMemoryContext(
                            c.Resolve<InterfaceType.Factory>(),
                            () => memCtx,
                            c.Resolve<MemoryImplementationType.MemoryFactory>());
                        Importer.LoadFromXml(memCtx, generatedAssembly.GetManifestResourceStream("Zetbox.Objects.MemoryImpl.FrozenObjects.xml"), "FrozenContext XML from Assembly");
                        memCtx.Seal();
                        return memCtx;
                    })
                    .As<IFrozenContext>()
                    .OnActivated(args =>
                    {
                        var manager = args.Context.Resolve<IMemoryActionsManager>();
                        manager.Init(args.Context.Resolve<IFrozenContext>());
                    })
                    .SingleInstance();
            }
            catch (FileNotFoundException ex)
            {
                Log.Warn("Could not load memory context", ex);
            }
            catch (Exception ex)
            {
                Log.Error("Error while loading memory context", ex);
                throw;
            }
        }
コード例 #2
0
        protected override void Load(ContainerBuilder moduleBuilder)
        {
            base.Load(moduleBuilder);

            moduleBuilder
            .RegisterType <MemoryImplementationType>()
            .As <MemoryImplementationType>()
            .As <ImplementationType>()
            .InstancePerDependency();

            moduleBuilder
            .RegisterType <MemoryContext>()
            .As <BaseMemoryContext>()
            .OnActivated(args =>
            {
                var manager = args.Context.Resolve <IMemoryActionsManager>();
                manager.Init(args.Context.Resolve <IFrozenContext>());
            })
            .InstancePerDependency();

            try
            {
                // TODO: Move to MemoryModule
                var generatedAssembly = Assembly.Load(GeneratedAssemblyName);
                moduleBuilder
                .Register(c =>
                {
                    FrozenMemoryContext memCtx = null;
                    memCtx = new FrozenMemoryContext(
                        c.Resolve <InterfaceType.Factory>(),
                        () => memCtx,
                        c.Resolve <MemoryImplementationType.MemoryFactory>());
                    Importer.LoadFromXml(memCtx, generatedAssembly.GetManifestResourceStream("Zetbox.Objects.MemoryImpl.FrozenObjects.xml"), "FrozenContext XML from Assembly");
                    memCtx.Seal();
                    return(memCtx);
                })
                .As <IFrozenContext>()
                .OnActivated(args =>
                {
                    var manager = args.Context.Resolve <IMemoryActionsManager>();
                    manager.Init(args.Context.Resolve <IFrozenContext>());
                })
                .SingleInstance();
            }
            catch (FileNotFoundException ex)
            {
                Log.Warn("Could not load memory context", ex);
            }
            catch (Exception ex)
            {
                Log.Error("Error while loading memory context", ex);
                throw;
            }
        }