神刀安全网

Michael Ridland: Announcing FreshMvvm 2.0

Today we’ve published up to nuget FreshMvvm 2.0 with some very anticipated new features.

IOC Container Lifetime Registration Options

We now support a fluent API for setting the object lifetime of object inside the IOC Container.

// By default we register concrete types as // multi-instance, and interfaces as singletons FreshIOC.Container.Register<MyConcreteType>(); // Multi-instance FreshIOC.Container.Register<IMyInterface, MyConcreteType>(); // Singleton   // Fluent API allows us to change that behaviour FreshIOC.Container.Register<MyConcreteType>().AsSingleton(); // Singleton FreshIOC.Container.Register<IMyInterface, MyConcreteType>().AsMultiInstance(); // Multi-instance 

As you can see below the IFreshIOC interface methods return the IRegisterOptions interface.

public interface IFreshIOC {     object Resolve(TyperesolveType);     IRegisterOptionsRegister<RegisterType>(RegisterTypeinstance) whereRegisterType : class;     IRegisterOptionsRegister<RegisterType>(RegisterTypeinstance, string name) whereRegisterType : class;     ResolveTypeResolve<ResolveType>() whereResolveType : class;     ResolveTypeResolve<ResolveType>(string name) whereResolveType : class;     IRegisterOptionsRegister<RegisterType, RegisterImplementation> ()         whereRegisterType : class         whereRegisterImplementation : class, RegisterType; } 

The interface that’s returned from the register methods is IRegisterOptions.

public interface IRegisterOptions {     IRegisterOptionsAsSingleton();     IRegisterOptionsAsMultiInstance();     IRegisterOptionsWithWeakReference();     IRegisterOptionsWithStrongReference();     IRegisterOptionsUsingConstructor<RegisterType>(Expression<Func<RegisterType>> constructor); } 

Switching out NavigationStacks on the Xamarin.Forms MainPage

There’s some cases in Xamarin.Forms you might want to run multiple navigation stacks. A good example of this is when you have a navigation stack for the authentication and a stack for the primary area of your application.

To begin with we can setup some names for our navigation containers.

public class NavigationContainerNames {     public const string AuthenticationContainer = "AuthenticationContainer";     public const string MainContainer = "MainContainer"; } 

Then we can create our two navigation containers and assign to the MainPage.

var loginPage = FreshMvvm.FreshPageModelResolver.ResolvePageModel<LoginViewModel>(); var loginContainer = new FreshNavigationContainer(loginPage, NavigationContainerNames.AuthenticationContainer);   var myPitchListViewContainer = new MainTabbedPage(NavigationContainerNames.MainContainer);   MainPage = loginContainer; 

Once we’ve set this up we can now switch out our navigation containers.

CoreMethods.SwitchOutRootNavigation(NavigationContainerNames.MainContainer); 

New public methods

CurrentNavigationServiceName and PreviousNavigationServiceName are both public methods, so you can access them if you need to.

Some features (recently released)

Multiple Navigation Services

Custom IOC Containers

WhenAny

Pushing different views

Clean up after page is Popped

Summary

As always this is available on nuget now!

If you have any questions please ask on forums.xamarin.com and send me a email.

You can also find some more docs on the github repo .

Thanks

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Michael Ridland: Announcing FreshMvvm 2.0

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址