# ServiceCollection

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-dependency-injection/struct-servicecollection/

**struct** · [`ferroui-dependency-injection`](/docs/0.5.0/api/ferroui-dependency-injection/) · v0.5.0

```rust
struct ServiceCollection
```

Ordered registrations; building a provider snapshots this collection.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L10)

## Members

- [`new`](#function-new)
- [`descriptors`](#function-descriptors)
- [`len`](#function-len)
- [`is_empty`](#function-is_empty)
- [`is_read_only`](#function-is_read_only)
- [`make_read_only`](#function-make_read_only)
- [`add`](#function-add)
- [`add_sequence`](#function-add_sequence)
- [`insert`](#function-insert)
- [`remove_at`](#function-remove_at)
- [`clear`](#function-clear)
- [`try_add`](#function-try_add)
- [`try_add_enumerable`](#function-try_add_enumerable)
- [`replace`](#function-replace)
- [`remove_all`](#function-remove_all)
- [`remove_all_keyed`](#function-remove_all_keyed)
- [`iter`](#function-iter)
- [`contains`](#function-contains)
- [`index_of`](#function-index_of)
- [`remove`](#function-remove)
- [`copy_to`](#function-copy_to)
- [`build_service_provider`](#function-build_service_provider)
- [`add_singleton_instance`](#function-add_singleton_instance)
- [`add_keyed_singleton_instance`](#function-add_keyed_singleton_instance)
- [`add_singleton`](#function-add_singleton)
- [`add_keyed_singleton`](#function-add_keyed_singleton)
- [`add_scoped`](#function-add_scoped)
- [`add_keyed_scoped`](#function-add_keyed_scoped)
- [`add_transient`](#function-add_transient)
- [`add_keyed_transient`](#function-add_keyed_transient)

<a id="function-new"></a>

### new

```rust
fn new() -> Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L27)

<a id="function-descriptors"></a>

### descriptors

```rust
fn descriptors(self: &Self) -> &[ServiceDescriptor]
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L30)

<a id="function-len"></a>

### len

```rust
fn len(self: &Self) -> usize
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L33)

<a id="function-is_empty"></a>

### is_empty

```rust
fn is_empty(self: &Self) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L36)

<a id="function-is_read_only"></a>

### is_read_only

```rust
fn is_read_only(self: &Self) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L39)

<a id="function-make_read_only"></a>

### make_read_only

```rust
fn make_read_only(self: &mut Self)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L42)

<a id="function-add"></a>

### add

```rust
fn add(self: &mut Self, descriptor: ServiceDescriptor) -> &mut Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L50)

<a id="function-add_sequence"></a>

### add_sequence

```rust
fn add_sequence(self: &mut Self, descriptors: impl IntoIterator<Item = ServiceDescriptor>) -> &mut Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L55)

<a id="function-insert"></a>

### insert

```rust
fn insert(self: &mut Self, index: usize, descriptor: ServiceDescriptor)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L63)

<a id="function-remove_at"></a>

### remove_at

```rust
fn remove_at(self: &mut Self, index: usize) -> ServiceDescriptor
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L67)

<a id="function-clear"></a>

### clear

```rust
fn clear(self: &mut Self)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L71)

<a id="function-try_add"></a>

### try_add

```rust
fn try_add(self: &mut Self, descriptor: ServiceDescriptor) -> &mut Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L75)

<a id="function-try_add_enumerable"></a>

### try_add_enumerable

```rust
fn try_add_enumerable(self: &mut Self, descriptor: ServiceDescriptor) -> &mut Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L86)

<a id="function-replace"></a>

### replace

```rust
fn replace(self: &mut Self, descriptor: ServiceDescriptor) -> &mut Self
```

Removes the first matching registration, then appends the replacement, as upstream.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L104)

<a id="function-remove_all"></a>

### remove_all

```rust
fn remove_all<S: ?Sized + 'static>(self: &mut Self) -> &mut Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L115)

<a id="function-remove_all_keyed"></a>

### remove_all_keyed

```rust
fn remove_all_keyed<S: ?Sized + 'static>(self: &mut Self, key: Option<ServiceKey>) -> &mut Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L118)

<a id="function-iter"></a>

### iter

```rust
fn iter(self: &Self) -> std::slice::Iter<'_, ServiceDescriptor>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L124)

<a id="function-contains"></a>

### contains

```rust
fn contains(self: &Self, descriptor: &ServiceDescriptor) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L127)

<a id="function-index_of"></a>

### index_of

```rust
fn index_of(self: &Self, descriptor: &ServiceDescriptor) -> Option<usize>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L130)

<a id="function-remove"></a>

### remove

```rust
fn remove(self: &mut Self, descriptor: &ServiceDescriptor) -> bool
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L135)

<a id="function-copy_to"></a>

### copy_to

```rust
fn copy_to(self: &Self, target: &mut [ServiceDescriptor], index: usize)
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L144)

<a id="function-build_service_provider"></a>

### build_service_provider

```rust
fn build_service_provider(self: &Self, options: ServiceProviderOptions) -> ServiceResult<ServiceProvider>
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L147)

<a id="function-add_singleton_instance"></a>

### add_singleton_instance

```rust
fn add_singleton_instance<S: ?Sized + 'static>(self: &mut Self, value: Rc<S>) -> &mut Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L153)

<a id="function-add_keyed_singleton_instance"></a>

### add_keyed_singleton_instance

```rust
fn add_keyed_singleton_instance<S: ?Sized + 'static>(self: &mut Self, key: Option<ServiceKey>, value: Rc<S>) -> &mut Self
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L156)

<a id="function-add_singleton"></a>

### add_singleton

```rust
fn add_singleton<S: ?Sized + 'static, F>(self: &mut Self, factory: F) -> &mut Self
where F: Fn(&ServiceProvider) -> ServiceResult<Rc<S>> + 'static
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L190)

<a id="function-add_keyed_singleton"></a>

### add_keyed_singleton

```rust
fn add_keyed_singleton<S: ?Sized + 'static, F>(self: &mut Self, key: Option<ServiceKey>, factory: F) -> &mut Self
where F: Fn(&ServiceProvider, Option<&ServiceKey>) -> ServiceResult<Rc<S>> + 'static
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L190)

<a id="function-add_scoped"></a>

### add_scoped

```rust
fn add_scoped<S: ?Sized + 'static, F>(self: &mut Self, factory: F) -> &mut Self
where F: Fn(&ServiceProvider) -> ServiceResult<Rc<S>> + 'static
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L191)

<a id="function-add_keyed_scoped"></a>

### add_keyed_scoped

```rust
fn add_keyed_scoped<S: ?Sized + 'static, F>(self: &mut Self, key: Option<ServiceKey>, factory: F) -> &mut Self
where F: Fn(&ServiceProvider, Option<&ServiceKey>) -> ServiceResult<Rc<S>> + 'static
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L191)

<a id="function-add_transient"></a>

### add_transient

```rust
fn add_transient<S: ?Sized + 'static, F>(self: &mut Self, factory: F) -> &mut Self
where F: Fn(&ServiceProvider) -> ServiceResult<Rc<S>> + 'static
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L192)

<a id="function-add_keyed_transient"></a>

### add_keyed_transient

```rust
fn add_keyed_transient<S: ?Sized + 'static, F>(self: &mut Self, key: Option<ServiceKey>, factory: F) -> &mut Self
where F: Fn(&ServiceProvider, Option<&ServiceKey>) -> ServiceResult<Rc<S>> + 'static
```



[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.DependencyInjection/service_collection.rs#L192)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- [`IServiceProviderFactory<ServiceCollection>`](/docs/0.5.0/api/ferroui-dependency-injection/trait-iserviceproviderfactory/)
- `Clone`
- `Default`
- [`IServiceCollection`](/docs/0.5.0/api/ferroui-dependency-injection/trait-iservicecollection/)
- `Index<usize>`
- `IndexMut<usize>`
- `IntoIterator`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
