Upload
chaturanga-ranatunga
View
287
Download
1
Embed Size (px)
Citation preview
How to Organise your Xamarin Solution by Adhering to
Common .NET Development Practices
Colombo Xamarin Meetuphttp://www.meetup.com/Colombo-Xamarin-Meetup/
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
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
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
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
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
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
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
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
What Can Be Improved ?
• One Layer is Dependent on Classes of Other Layer
• Tight Coupling
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
DependencyService
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
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
Improvement 4Using DI to Replace DependencyService
Sitecore CMS
• One of the leading Content Management System in the world
• Provides a Mobile SDK for Xamarin
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
What We Did NOT Discussed
• MVVM Pattern
• Xamarin INotifyPropertyChange Interface
• Object-to-Object Mappers
Thank You!Source Code :
https://github.com/chaturangar/xamarin-footsteps