GithubHelp home page GithubHelp logo

gonzalonm / xamarin-forms-clean Goto Github PK

View Code? Open in Web Editor NEW
30.0 4.0 15.0 825 KB

Sample Xamarin.Forms application using Clean Architecture

License: Apache License 2.0

C# 100.00%
xamarin xamarin-forms sqlite clean-architecture architecture rx reactivex rxnet

xamarin-forms-clean's Introduction

xamarin-forms-clean

Sample Xamarin.Forms application using Clean Architecture. Inspired in the done work by Fernando Cejas

Used NuGet Packages

sqlite-net-pcl: Nice ORM to store data with SQLite

Xam.Plugin.Connectivity: Plugin to detect network state

System.Reactive.Linq: Rx.NET plugin

Clean Architecture

You can review the concepts of Clean Architecture in this site.

Principles

1. Independent of Frameworks. The architecture does not depend on the existence of some library of feature laden software. This allows you to use such frameworks as tools, rather than having to cram your system into their limited constraints.

2. Testable. The business rules can be tested without the UI, Database, Web Server, or any other external element.

3. Independent of UI. The UI can change easily, without changing the rest of the system. A Web UI could be replaced with a console UI, for example, without changing the business rules.

4. Independent of Database. You can swap out Oracle or SQL Server, for Mongo, BigTable, CouchDB, or something else. Your business rules are not bound to the database.

5. Independent of any external agency. In fact your business rules simply don’t know anything at all about the outside world.

Alt text

Code sample

Observable class creation from API call.

return Observable.Create<List<CityEntity>>((emitter) =>
  {
    var json = GetAllCitiesFromApi();
    if (json != null)
    {
      emitter.OnNext(CityEntitySerializer.FromJson(json));
      emitter.OnCompleted();
    }
    else
    {
      emitter.OnError(new Exception("Cities were not found"));
    }
  });

Transformation from entity to a model class using a mapper

Mapper

	public class CityMapper : BaseMapper<City, CityEntity>
	{
		public override City Transform(CityEntity entity)
		{
			var city = new City
			{
				Image = entity.ImageLink,
				Name = entity.Name
			};
			return city;
		}
	}

Transform a list of entities into a list of model class

dataSource.Cities().Select(x => Mapper.TransformList(x));

Usecase execution

		public void Execute(IObserver<T> observer, P param)
		{
			if (observer != null)
			{
				Task.Run(() => 
				{
					IObservable<T> observable = BuildUseCaseObservable(param);
					AddDisposable(observable.SubscribeSafe(observer));
				});
			}
		}

Collaborate

You can collaborate with this project. Check the guidelines to contribute.

License

Copyright 2018 Gonzalo Martin

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

xamarin-forms-clean's People

Contributors

gonzalonm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

xamarin-forms-clean's Issues

Use Reactive

We should think in use reactive instead of proactive design. Thoughts? External libraries?

MVP vs MVVM

What pattern we should use here? Currently the project intents to use MVP but we can consider move it to MVVM if there is a good cause :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.