lunes, 21 de octubre de 2019

Downloading IntelliSense index for nuget.org

I've recently updated my Visual Studio IDE from v.2017 to v.2019.

Since then, a background task was permantly running under the label "Downloading IntelliSense index for nuget.org".
A few entries appear googling the issue, and the official answer always is "update to the latest version and try again". And obviously, that doesn't work. 

Then, I've found this entry from Lars Wilhelmsen:

Create an DWORD (32-bit) value called Enabled and set it to 0 under:
HKCU\SOFTWARE\Microsoft\VisualStudio\16.0_6cf1d688\Roslyn\Features\SymbolSearch
The 'Roslyn\Features\SymbolSearch' keys have to be created as well. The '16.0_6cf1d688' version number might be different on your machine.

And magically, the problem is solved.

martes, 1 de octubre de 2019

MVVM with SQLite: solution model

When implementing some design pattern or architecture that requires some concentration and learning from me, I like to document the process to have it as a reference in the future, and also to share it with others who want to travel the same path.

In this case, it's about how I applied the Model-View-ViewModel pattern along with SQLite persistence data, in my mobile application developed with Xamarin Forms.

I will just list the high-level steps of the process, which is illustrated in the class diagram below. It should be clarified that the diagram only reflects those attributes and behaviors of the class model that I consider relevant for the explanation, because, clearly, the complete model is much more extensive.

On the one hand I added an ExtendedBindableObject class, which derives from BindableObject, and adds the automatic notification of the PropertyChanged event, when a ViewModel undergoes some change in its exposed properties.

From the ExtendedBindableObject class, derive BaseViewModel, which will serve as the basis for all the ViewModels of each object to represent.

The ViewModels scheme in my case, speaking for now for simple objects, consists of a ViewModel with a collection of objects, another to add new objects, and another one to show the details of a given object, which also allows you to delete or modify its attributes.

For each of the ViewModels detailed above, a View corresponds, implemented within the Xamarin Forms model as a ContentPage.

When the View is created, the corresponding ViewModel constructor is called, and a new instance of the CrudService service (which implements the ICrudService interface) is passed, which the ViewModel contains. In this way, the dependency injection pattern is used (a particular case of the control inversion pattern) indicating to the ViewModel what service to use to access the data layer.

The CrudService service, in turn, is responsible for making calls to the data layer, represented by the AppDatabase class.

This is roughly the complete picture needed to implement MVVM together with SQLite. I had to spend several hours reading, and then testing, until it was working, but it leaves me happy to be aligned with the recommended practices.

If the promise of scalability and cleaner growth of the application, which this pattern proposes, is fulfilled, time will tell.

MVVM con SQLite: modelo de solución

Cuando implementar algún patrón de diseño o un arquitectura que requiere cierta concentración y aprendizaje de mi parte, me gusta documentar el proceso para tenerlo como referencia en el futuro, y también para compartirlo con otros que quieran transitar el mismo camino.

En este caso, se trata de cómo apliqué el patrón Model-View-ViewModel junto con persistencia de datos SQLite, en mi aplicación móvil desarrollada con Xamarin Forms.

Me limitaré a enumerar lo pasos a alto nivel del proceso, que queda ilustrado en el diagrama de clases que acompaña el artículo. Cabe aclarar, que el diagrama sólo refleja aquellos atributos y comportamientos del modelo de clases que considero relevantes para la explicación, porque, claramente, el modelo completo es mucho más extenso.

Por un lado agregué una clase ExtendedBindableObject, que deriva de BindableObject, y agrega la notificación automática del evento PropertyChanged, cuando un ViewModel sufre algún cambio en sus propiedades expuestas.

De la clase ExtendedBindableObject, deriva BaseViewModel, que servirá de base para todas los ViewModels de cada objeto a representar.

El esquema de ViewModels en mi caso, hablando por ahora para objetos simples, consta de un ViewModel con una colección de objetos, otro para agregar nuevos objetos, y otro más para mostrar los detalles de un objeto dado, que además permite borrar o modificar sus atributos.

Para cada uno de los ViewModels detallados anteriormente, se corresponde un View, implementado dentro del modelo de Xamarin Forms como un ContentPage.

Al momento de crearse el View, se llama al constructor del ViewModel correspondiente, y se le pasa una nueva instancia del servicio CrudService (que implementa la interfaz ICrudService), que el ViewModel contiene. De este modo, se hace uso del patrón de inyección de dependencias (un caso particular del patrón inversión de control) indicando al ViewModel qué servicio utilizar para acceder a la capa de datos.

El servicio CrudService a su vez, se encarga de hacer las llamadas a la capa de datos, representada por la clase AppDatabase.

Esto es a grandes rasgos el cuadro completo necesario para implementar MVVM junto con SQLite. Tuve que invertir varias horas de lectura, y luego de pruebas, hasta dejarlo funcionando, pero me deja conforme estar alineado con las prácticas recomendadas.

Si se cumple luego la promesa de escalabilidad y crecimiento más limpio de la aplicación, que este patrón propone, el tiempo dirá.