Slide of my presentation at Colombo Xamarin Meetups on July 2016 where we discussed How to Structure Your Xamarin Solution by Adhering to Common .NET Practices. We talked about Repository Pattern, Dependency Injection and Sitecore Mobile SDK for Xamarin
Powerful Love Spells in Arkansas, AR (310) 882-6330 Bring Back Lost Lover
How to Structure Your Xamarin Solution by Adhering to Common .NET Practices - Xamarin Meetup Presentation
1. How to Organise your Xamarin
Solution by Adhering to Common
.NET Development Practices
Colombo Xamarin Meetup
http://www.meetup.com/Colombo-Xamarin-Meetup/
2. 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
3. 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
4. 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
5. 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
6. Improvement 1
Moving 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
7. 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
8. Improvement 2
Moving Data Storage Functionality Into
Repository Layer
• Ease to Maintain
• Ease to Replace Storage Media
• Can Start Developing
Functionality without Waiting for
Storage Functionality
9.
10. 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
11. What Can Be Improved ?
• One Layer is Dependent on Classes of Other Layer
• Tight Coupling
12. Improvement 3
Dependency Injection
• Used to resolve dependencies
• DI Containers : Autofac, Ninject, StructureMap, Castle Windsor, etc
• In this example, we use Autofac 3.5.2
• Light-Weight
15. 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
16.
17. 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
20. Sitecore CMS
• One of the leading Content
Management System in the
world
• Provides a Mobile SDK for
Xamarin
21. 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
22. What We Did NOT
Discussed
• MVVM Pattern
• Xamarin
INotifyPropertyChange
Interface
• Object-to-Object
Mappers