How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup...

24
How to Organise your Xamarin Solution by Adhering to Common .NET Development Practices Colombo Xamarin Meetup http://www.meetup.com/Colombo-Xamarin-Meetup/

Transcript of How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup...

Page 1: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

How to Organise your Xamarin Solution by Adhering to

Common .NET Development Practices

Colombo Xamarin Meetuphttp://www.meetup.com/Colombo-Xamarin-Meetup/

Page 2: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

About Me• Freelance Sitecore Consultant

• Sitecore MVP 2016

• Blog - http://sitecorefootsteps.blogspot.com

• YouTube - Sitecore for Dummies

• Initiator & Co-Founder - Sitecore User Group Sri Lanka

Page 3: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

What We Going To Discuss

• Discuss a Simple Application to implement best practices

• How and why we implement Repository Pattern into the solution

• Dependency Injection

• Xamarin Forms Dependency Service

• Example application with Xamarin for Sitecore which uses Sitecore Mobile API

Page 4: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

Simple Application• Home Screen

• Calculation Screen

• Two Input Fields

• On Calculate button clicked, Results Display

• Results keep in a Repository (memory in this case)

• When your return, you can see the last calculated result

Page 5: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

What Can Be Improved ?

• UI and Logic Layer in one place

• Code maintenance is hard

• Hard to work in same functionality for two developers (ex: UI & Backend Devs)

• Hard to replace UI with new Technology

Page 6: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

Improvement 1Moving Application Logic into a

Service Layer

• Easy to Maintain

• Easy for Backend and Front-end Developers to Work in Same Functionality

• Easy to Replace UI Layer

Page 7: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

What Can Be Improved ?

• Data Storage is also Handled in Service Layer

• Hard to Change Storage Mechanism

• Service Layer implementation needs to wait till Full Storage functionality implemented

Page 8: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

Improvement 2Moving Data Storage Functionality

Into Repository Layer

• Ease to Maintain

• Ease to Replace Storage Media

• Can Start Developing Functionality without Waiting for Storage Functionality

Page 9: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation
Page 10: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

Repository Pattern

• Separates Data Access Layer from Logic Layer

• Retrieve data from data sources and convert them to Domain Objects, and pass them to Service Layer

Page 11: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

What Can Be Improved ?

• One Layer is Dependent on Classes of Other Layer

• Tight Coupling

Page 12: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

Improvement 3Dependency Injection

• Used to resolve dependencies

• DI Containers : Autofac, Ninject, StructureMap, Castle Windsor, etc

• In this example, we use Autofac 3.5.2

• Light-Weight

Page 13: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation
Page 14: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

DependencyService

Page 15: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

DependencyService• Allow to Register different implementation of an Interface for

each Target Platform• Framework uses correct implementation depending on the

platform• Need to place Dependency Attribute before the Class

Implementation

Page 16: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation
Page 17: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

Disadvantages of DependencyService

• It is considered as Anti-Pattern• Adding a Dependency Attribute on Classes

tightly couples DI framework being used• Hard to write Unit Tests

Page 18: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

Improvement 4Using DI to Replace DependencyService

Page 19: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation
Page 20: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

Sitecore CMS

• One of the leading Content Management System in the world

• Provides a Mobile SDK for Xamarin

Page 21: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

Simple App Calling

Sitecore Mobile SDK

• Sitecore Mobile SDK - a Portable .NET Library

• Provides an interface to work on Sitecore CMS

• Need to Implement your application methods as async calls

Page 22: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

What We Did NOT Discussed

• MVVM Pattern

• Xamarin INotifyPropertyChange Interface

• Object-to-Object Mappers

Page 23: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation
Page 24: How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation

Thank You!Source Code :

https://github.com/chaturangar/xamarin-footsteps