> For the complete documentation index, see [llms.txt](https://xztech.gitbook.io/servicex/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xztech.gitbook.io/servicex/tips/ru-he-shou-dong-huo-qu-service-shi-li.md).

# 如何手动获取Service实例？

某些情况下我们可能需要手动获取某Service的实例而不是通过hooks，可以使用container底层api：

```typescript
import { Injectable, container, Service, Singleton } from 'service-x'

@Injectable()
class DemoService extends Service<number> {
    defaultState: number = 0
}

// get the instance of DemoService with scope Singleton
const service = container.resolveInScope(DemoService, Singleton)

console.log(service.getState()) // 0
```
