當前位置: 首頁>>代碼示例>>Python>>正文


Python Container.resolve方法代碼示例

本文整理匯總了Python中mtm.ioc.Container.resolve方法的典型用法代碼示例。如果您正苦於以下問題:Python Container.resolve方法的具體用法?Python Container.resolve怎麽用?Python Container.resolve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mtm.ioc.Container的用法示例。


在下文中一共展示了Container.resolve方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _main

# 需要導入模塊: from mtm.ioc import Container [as 別名]
# 或者: from mtm.ioc.Container import resolve [as 別名]
def _main():
    # Here we split out some functionality into various methods
    # so that other python code can make use of them
    # if they want to extend projeny
    parser = argparse.ArgumentParser(description='Unity Package Manager')
    addArguments(parser)

    argv = sys.argv[1:]

    # If it's 2 then it only has the -cfg param
    if len(argv) == 0:
        parser.print_help()
        sys.exit(2)

    args = parser.parse_args(sys.argv[1:])

    Container.bind('LogStream').toSingle(LogStreamFile)
    Container.bind('LogStream').toSingle(LogStreamConsole, args.verbose, args.veryVerbose)

    if args.createConfig:
        _createConfig()
    else:
        if args.configPath:
            assertThat(os.path.isfile(args.configPath), "Could not find config file at '{0}'", args.configPath)
            mainConfigPath = args.configPath
        else:
            mainConfigPath = findMainConfigPath()

        installBindings(mainConfigPath)
        installPlugins()

        Container.resolve('PrjRunner').run(args)
開發者ID:Ariequ,項目名稱:Projeny,代碼行數:34,代碼來源:Prj.py

示例2: _request

# 需要導入模塊: from mtm.ioc import Container [as 別名]
# 或者: from mtm.ioc.Container import resolve [as 別名]
    def _request(self):
        if not Container.hasBinding(self._identifier):
            return self._default

        obj = Container.resolve(self._identifier)
        self._assertion(obj)
        return obj
開發者ID:AcamTech,項目名稱:Zenject,代碼行數:9,代碼來源:Inject.py

示例3: test1

# 需要導入模塊: from mtm.ioc import Container [as 別名]
# 或者: from mtm.ioc.Container import resolve [as 別名]
    def test1(self):
        config = {
            'PathVars': {
                'foo': 'yep [bar]',
                'bar': 'result2',
                'nest1': 'asdf [foo]',
            }
        }
        Container.bind('Config').toSingle(Config, [config])

        Container.bind('VarManager').toSingle(VarManager)

        pathMgr = Container.resolve('VarManager')

        assertThat(pathMgr.hasKey('foo'))
        assertThat(not pathMgr.hasKey('asdf'))
        assertThat(pathMgr.tryGet('bobsdf') == None)
        assertThat(pathMgr.expand('before [bar] after') == 'before result2 after')
        assertThat(pathMgr.expand('before [foo] after') == 'before yep result2 after')

        assertThat(not pathMgr.hasKey('qux'))
        pathMgr.add('qux', 'sadf')
        assertThat(pathMgr.hasKey('qux'))
        assertThat(pathMgr.expand('[qux]') == 'sadf')

        assertThat(pathMgr.expand('[nest1]') == 'asdf yep result2')

        print('Done')
開發者ID:AcamTech,項目名稱:Zenject,代碼行數:30,代碼來源:TestVarManager.py

示例4: testMultiple

# 需要導入模塊: from mtm.ioc import Container [as 別名]
# 或者: from mtm.ioc.Container import resolve [as 別名]
    def testMultiple(self):

        Container.bind('Config').toSingle(Config, loadYamlFilesThatExist(ScriptDir + '/ExampleConfig.yaml', ScriptDir + '/ExampleConfig2.yaml'))

        config = Container.resolve('Config')

        # From 1
        assertIsEqual(config.getString('receipt'), 'Oz-Ware Purchase Invoice')

        # From 2
        assertIsEqual(config.getString('thing1'), 'Foo')

        # Second one should override
        assertIsEqual(config.getString('foo2'), 'ipsum')

        assertIsEqual(config.getString('nest1', 'firstName'), 'Dorothy')

        # Test concatenating lists together
        assertIsEqual(config.getList('list1'), ['lorem', 'ipsum', 'asdf', 'joe', 'frank'])

        # Test concatenating dictionaries together
        assertIsEqual(config.getDictionary('dict1'), {'joe': 5, 'mary': 15, 'kate': 5, 'jim': 10})

        assertIsEqual(config.tryGetDictionary(None, 'asdfasdfasdf'), None)
        assertIsEqual(config.tryGetDictionary({ 5: 1 }, 'asdfasdfasdf'), { 5: 1 })

        assertIsEqual(config.tryGetList(None, 'asdfasdfasdf'), None)
        assertIsEqual(config.tryGetList([1, 2], 'asdfasdfasdf'), [1, 2])

        assertIsEqual(config.tryGetBool(False, 'zxvzasdfasdfasdf'), False)
        assertIsEqual(config.tryGetBool(True, 'zxvzasdfasdfasdf'), True)

        assertIsEqual(config.tryGetString('asdf', 'zxvzasdfasdfasdf'), 'asdf')

        assertIsEqual(config.tryGetInt(5, 'zxvzasdfasdfasdf'), 5)
開發者ID:Ariequ,項目名稱:Projeny,代碼行數:37,代碼來源:TestConfigYaml.py

示例5: testUseDefault

# 需要導入模塊: from mtm.ioc import Container [as 別名]
# 或者: from mtm.ioc.Container import resolve [as 別名]
    def testUseDefault(self):
        Container.bind('Foo').to(1)
        Container.bind('Test1').toSingle(Test1)

        test1 = Container.resolve('Test1')

        self.assertEqual(test1.foo, 1)
        self.assertEqual(test1.bar, 5)
開發者ID:AcamTech,項目名稱:Zenject,代碼行數:10,代碼來源:TestOptionalInjection.py

示例6: test1

# 需要導入模塊: from mtm.ioc import Container [as 別名]
# 或者: from mtm.ioc.Container import resolve [as 別名]
    def test1(self):
        assertThat(False, "TODO")
        #Container.bind('Config').toSingle(ConfigXml)
        Container.bind('VarManager').toSingle(VarManager)
        Container.bind('SystemHelper').toSingle(SystemHelper)
        Container.bind('Logger').toSingle(Logger)

        self._test1(Container.resolve('SystemHelper'))
開發者ID:AcamTech,項目名稱:Zenject,代碼行數:10,代碼來源:TestSystemHelper.py

示例7: testOverrideDefault

# 需要導入模塊: from mtm.ioc import Container [as 別名]
# 或者: from mtm.ioc.Container import resolve [as 別名]
    def testOverrideDefault(self):
        Container.bind('Foo').to(2)
        Container.bind('Test1').to(Test1)
        Container.bind('Bar').to(3)

        test1 = Container.resolve('Test1')

        self.assertEqual(test1.foo, 2)
        self.assertEqual(test1.bar, 3)
開發者ID:AcamTech,項目名稱:Zenject,代碼行數:11,代碼來源:TestOptionalInjection.py

示例8: testSpecialChars

# 需要導入模塊: from mtm.ioc import Container [as 別名]
# 或者: from mtm.ioc.Container import resolve [as 別名]
    def testSpecialChars(self):
        Container.bind('Config').toSingle(Config, loadYamlFilesThatExist(ScriptDir + '/ExampleConfig.yaml', ScriptDir + '/ExampleConfig2.yaml'))

        config = Container.resolve('Config')

        assertIsEqual(config.tryGetString(None, 'foo4'), 'asdf')

        assertIsEqual(config.tryGetString(None, 'foo5'), 'zxcv')

        assertIsEqual(config.tryGetString(None, 'foo6'), 'asdf')
        assertIsEqual(config.tryGetString(None, 'foo7'), 'zxcv')
開發者ID:Ariequ,項目名稱:Projeny,代碼行數:13,代碼來源:TestConfigYaml.py

示例9: testSimple

# 需要導入模塊: from mtm.ioc import Container [as 別名]
# 或者: from mtm.ioc.Container import resolve [as 別名]
    def testSimple(self):
        yamlPath = ScriptDir + '/ExampleConfig.yaml'

        Container.bind('Config').toSingle(Config, loadYamlFilesThatExist(yamlPath))

        config = Container.resolve('Config')

        assertIsEqual(config.getString('date'), '2012-08-06')
        assertIsEqual(config.getString('receipt'), 'Oz-Ware Purchase Invoice')

        assertIsEqual(config.getList('places'), ['New Jersey', 'New York'])
        assertRaisesAny(lambda: config.getString('places'))
        assertRaisesAny(lambda: config.getDictionary('places'))

        assertIsEqual(config.getDictionary('customer'),
          {'first_name': 'Dorothy', 'family_name': 'Gale'})

        # Tests YAML references
        assertIsEqual(config.getString('foo1'), config.getString('receipt'))
開發者ID:Ariequ,項目名稱:Projeny,代碼行數:21,代碼來源:TestConfigYaml.py

示例10: testOutputToConsole

# 需要導入模塊: from mtm.ioc import Container [as 別名]
# 或者: from mtm.ioc.Container import resolve [as 別名]
    def testOutputToConsole(self):
        self._installBindings()
        log = Container.resolve('Logger')

        with log.heading("heading 1"):
            log.info("test of params: {0}", 5)

            with log.heading("heading 2"):
                log.error("test of params: {0}", 5)
                log.good("test of params: {0}", 5)

            log.info("test of params: {0}", 5)
            log.info("info 1")
            log.error("error 1")
            log.good("good 1")
            log.info("info 2")

            with log.heading("heading 2"):
                log.info("info 3")
                log.good("Done")
開發者ID:Ariequ,項目名稱:Projeny,代碼行數:22,代碼來源:TestLogger.py

示例11: log

# 需要導入模塊: from mtm.ioc import Container [as 別名]
# 或者: from mtm.ioc.Container import resolve [as 別名]
        if parsedMessage:
            return LogType.Info, parsedMessage

        parsedMessage = self.tryMatchPattern(message, self.debugMaps, self.debugPatterns)
        if parsedMessage:
            return LogType.Debug, parsedMessage

        return LogType.Noise, message


if __name__ == "__main__":
    import mtm.ioc.Container as Container

    class Log1:
        def log(self, logType, message):
            print("log 1: " + message)

    class Log2:
        def log(self, logType, message):
            print("log 2: " + message)

    Container.bind("LogStream").toSingle(Log1)
    Container.bind("LogStream").toSingle(Log2)

    Container.bind("Logger").toSingle(Logger)

    logger = Container.resolve("Logger")

    logger.info("test info")
    logger.error("test error")
開發者ID:Cyberbanan,項目名稱:Projeny,代碼行數:32,代碼來源:Logger.py

示例12: len

# 需要導入模塊: from mtm.ioc import Container [as 別名]
# 或者: from mtm.ioc.Container import resolve [as 別名]
        if len(args) > 0:
            msg = msg.format(*args)

        if logType == LogType.Heading:
            msg += '...'

        for stream in self._streams:
            stream.log(logType, msg)

if __name__ == '__main__':
    import mtm.ioc.Container as Container

    class Log1:
        def log(self, logType, msg):
            print('log 1: ' + msg)

    class Log2:
        def log(self, logType, msg):
            print('log 2: ' + msg)

    Container.bind('LogStream').toSingle(Log1)
    Container.bind('LogStream').toSingle(Log2)

    Container.bind('Logger').toSingle(Logger)

    logger = Container.resolve('Logger')

    logger.info('test info')
    logger.error('test error')
開發者ID:AcamTech,項目名稱:Zenject,代碼行數:31,代碼來源:Logger.py

示例13: test1

# 需要導入模塊: from mtm.ioc import Container [as 別名]
# 或者: from mtm.ioc.Container import resolve [as 別名]
    def test1(self):
        Container.bind('Foo1').to(Foo1, 7)
        Container.bind('Foo2').to(Foo2, 6)

        foo2 = Container.resolve('Foo2')
        foo2.Start()
開發者ID:AcamTech,項目名稱:Zenject,代碼行數:8,代碼來源:TestCircularDependencies.py


注:本文中的mtm.ioc.Container.resolve方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。