-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
209 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -265,4 +265,7 @@ secrets.json | |
appsettings.json | ||
|
||
# MFractor | ||
.mfractor/ | ||
.mfractor/ | ||
|
||
# MkDocs Generated Site | ||
site/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Errors happen when navigating. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
Prism's IPageBehaviorFactory is a great way to apply some custom behaviors on to pages either globally or with a little business logic. The Extended Prism.Forms package uses a custom PageBehaviorFactory. In addition to the normal behaviors that Prism applies to your Pages behind the scenes, the Extended version provides support for the following: | ||
|
||
- Globally adding Platform Specifics on: | ||
- SetToolbarPlacement on Android TabbedPage | ||
- Use Safe Area on iOS | ||
- PreferLargeTitles on iOS | ||
- A custom behavior that changes the Title of a TabbedPage to always match the actively selected Tab | ||
|
||
To control these features you simply need to register an implementation of `IPageBehaviorFactoryOptions`. | ||
|
||
!!! note "Note" | ||
A default instance is provided automatically that enables all of these features. | ||
|
||
```c# | ||
internal class MyPageBehaviorFactoryOptions : IPageBehaviorFactoryOptions | ||
{ | ||
public bool UseBottomTabs => true; | ||
|
||
public bool UseSafeArea => true; | ||
|
||
public bool UseChildTitle => true; | ||
|
||
public bool PreferLargeTitles => true; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Delegate Registration | ||
|
||
Sometimes you really need a bit more power behind constructing a service. For these times you may find yourself in one of the following scenarios: | ||
|
||
- You just need to perform some Action like: | ||
|
||
```c# | ||
public static IBackendService CreateBackendService() | ||
{ | ||
return new BackendService | ||
{ | ||
Uri = Constants.BackendUri | ||
}; | ||
} | ||
``` | ||
|
||
- You need to resolve something to do a more complex look up and properly construct your type: | ||
|
||
```c# | ||
public static IBackendService CreateBackendService(IContainerProvider containerProvider) | ||
{ | ||
var options = containerProvider.Resolve<IOptions>(); | ||
return containerProvider.Resolve<IBackendService>((typeof(Uri), options.BackendUri)); | ||
} | ||
``` | ||
|
||
!!! note "Note" | ||
This supports both Delegates with `IContainerProvider` and `IServiceProvider` | ||
|
||
Regardless of which way you need to resolve service the Delegate Registration extensions really help out for those scenarios where you can't just simply pass a raw implementing type. | ||
|
||
```c# | ||
protected override void RegisterTypes(IContainerRegistry containerRegistry) | ||
{ | ||
containerRegistry.RegisterDelegate<IFoo>(FooFactory); | ||
containerRegistry.RegisterDelegate<IBar>(BarFactory); | ||
} | ||
|
||
private static IFoo FooFactory() => new Foo(); | ||
|
||
private static IBar BarFactory(IContainerProvider container) | ||
{ | ||
var options = container.Resolve<IOptions>(); | ||
return new Bar { HasCode = options.HasCode }; | ||
} | ||
|
||
private static IBar BarFactory(IServiceProvider serviceProvider) | ||
{ | ||
var options = serviceProvider.GetService<IOptions>(); | ||
return new Bar { HasCode = options.HasCode }; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# RegisterMany | ||
|
||
One of the very powerful new methods provided by the Container Extensions is the `RegisterMany` and `RegisterManySingleton` method. This really can help you reduce how much boilerplate code you need to write and provide some advanced scenarios. So what is it? | ||
|
||
```c# | ||
public interface IFoo | ||
{ | ||
void DoFoo(); | ||
} | ||
|
||
public interface IBar | ||
{ | ||
void DoBar(); | ||
} | ||
``` | ||
|
||
To start let's assume that you have 2 interfaces like the ones above `IFoo` and `IBar`. Now let's assume that you have a single implementing type like: | ||
|
||
```c# | ||
public class FooBar : IFoo, IBar | ||
{ | ||
|
||
public void DoFoo() | ||
{ | ||
Console.WriteLine("Doing foo"); | ||
} | ||
|
||
public void DoBar() | ||
{ | ||
Console.WriteLine("Doing Bar"); | ||
} | ||
} | ||
``` | ||
|
||
Without the Container Extensions you might have a transient registration like: | ||
|
||
```c# | ||
containerRegistry.Register<IFoo, FooBar>(); | ||
containerRegistry.Register<IBar, FooBar>(); | ||
``` | ||
|
||
While this may not be such a big deal, it suddenly starts making more sense when we expect the use of a singleton. The issue here is that if we were to do something similar to this to register a Singleton traditionally like: | ||
|
||
```c# | ||
containerRegistry.RegisterSingleton<IFoo, FooBar>(); | ||
containerRegistry.RegisterSingleton<IBar, FooBar>(); | ||
``` | ||
|
||
We are under the impression that we have a singleton here. The issue of course is that if you check for equality like: | ||
|
||
```c# | ||
if(Container.Resolve<IFoo>() == Container.Resolve<IBar>()) | ||
{ | ||
Console.WriteLine("Foo and Bar are the same instance"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Foo and Bar are difference instances"); | ||
} | ||
``` | ||
|
||
We might expect that the first case would evaluate to true that Foo and Bar are the same instance, but in reality they are two different instances. The issue isn't that we somehow didn't register them as a singleton because if you resolve IFoo twice and do the same equality check it will actually evaluate to true because they would be the same instance. However, Foo and Bar are different instances because they were registered separately. This is where `RegisterManySingleton` really shines. If we were to update our registration like: | ||
|
||
```c# | ||
// Implicitly registers any implemented interfaces | ||
containerRegistry.RegisterManySingleton<FooBar>(); | ||
|
||
// Explicitly registers implemented interfaces | ||
containerRegistry.RegisterManySingleton<FooBar>(typeof(IFoo), typeof(IBar)) | ||
``` | ||
|
||
We can now perform the same equality check above only this time `IFoo` and `IBar` would equal one another because they would both have been resolved from the same instance of the `FooBar` implementation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Scoping | ||
|
||
TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters