# ViewRegistrations

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-reactiveui/binding/view/struct-viewregistrations/

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

```rust
struct ViewRegistrations
```

The views of view models, collected into one [`GeneratedViewDispatch`](/docs/0.5.0/api/ferroui-reactiveui/binding/view/type_alias-generatedviewdispatch/): what upstream's source
generator builds from the classes that implement `IViewFor<T>`.

```
use ferroui_reactiveui::{view_for, DefaultViewLocator, IViewLocator, ViewContract, ViewRegistrationOptions, ViewRegistrations};
use std::any::Any;
use std::cell::RefCell;
use std::rc::Rc;

struct TodoViewModel;

#[derive(Default)]
struct TodoView {
    view_model: RefCell<Option<Rc<TodoViewModel>>>,
}
view_for!(TodoView, TodoViewModel, view_model);

ViewRegistrations::new()
    .register::<TodoViewModel, TodoView>(ViewRegistrationOptions::new())
    .register::<TodoViewModel, TodoView>(ViewRegistrationOptions::new().with_contract(ViewContract::new("compact")))
    .apply();

let view = DefaultViewLocator::new().resolve_view(Some(Rc::new(TodoViewModel) as Rc<dyn Any>), Some("compact"));
assert!(view.is_some());
```

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/view/view_registrations.rs#L85)

## Members

- [`new`](#function-new)
- [`register`](#function-register)
- [`register_with`](#function-register_with)
- [`dispatch`](#function-dispatch)
- [`apply`](#function-apply)

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

### new

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

No registration.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/view/view_registrations.rs#L97)

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

### register

```rust
fn register<VM: 'static, V: IViewForOf<VM> + Default>(self: Self, options: ViewRegistrationOptions) -> Self
```

Registers the view type `V` for the view model type `VM`, created with `Default`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/view/view_registrations.rs#L102)

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

### register_with

```rust
fn register_with<VM: 'static, V: IViewForOf<VM>>(self: Self, factory: impl Fn() -> Rc<V> + 'static, options: ViewRegistrationOptions) -> Self
```

Registers the views `factory` creates for the view model type `VM`. A registration with
`ExcludeFromViewRegistration` is skipped; one with `SingleInstanceView` creates its view
once, on its first resolution.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/view/view_registrations.rs#L109)

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

### dispatch

```rust
fn dispatch(self: Self) -> GeneratedViewDispatch
```

The lookup of the registered views: the first registration of the type of the view model
under the contract gives the view.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/view/view_registrations.rs#L130)

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

### apply

```rust
fn apply(self: Self)
```

Registers the lookup with `DefaultViewLocator::set_generated_view_dispatch`, as upstream's
generated module initializer does.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/binding/view/view_registrations.rs#L143)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `Default`
- `Debug`

## Availability

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