AzureMobileClient.Helpers
AzureMobileClient.Helpers is a lightweight toolkit for using the Microsoft Azure Mobile Client. It provides a set of abstractions and base classes that are based originally on the Samples from Adrian Hall, along with a few tweaks to follow best practices with an interface based design.
Note that this library has been aligned with the Microsoft.Azure.Mobile.Client and is offered using NetStandard1.4 and as such is not compatible with traditional PCL projects. For this reason, it is recommended that you check out the Prism Templates I have available for dotnet new
which use a NetStandard1.4 common library for the shared code.
Support
If this project helped you reduce time to develop and made your app better, please help support this project.
Resources
Setting up the library for Dependency Injection
The following examples are based on using DryIoc in a Prism Application:
protected override void RegisterTypes()
{
// ICloudTable is only needed for Online Only data
Container.Register(typeof(ICloudTable<>), typeof(AzureCloudTable<>), Reuse.Singleton);
Container.Register(typeof(ICloudSyncTable<>), typeof(AzureCloudSyncTable<>), Reuse.Singleton);
Container.UseInstance<IPublicClientApplication>(new PublicClientApplication(Secrets.AuthClientId, AppConstants.Authority)
{
RedirectUri = AppConstants.RedirectUri
});
Container.RegisterMany<AADOptions>(reuse: Reuse.Singleton,
serviceTypeCondition: type =>
type == typeof(IAADOptions) ||
type == typeof(IAADLoginProviderOptions));
Container.Register<IAzureCloudServiceOptions, AppServiceContextOptions>(Reuse.Singleton);
Container.RegisterMany<AppDataContext>(reuse: Reuse.Singleton,
serviceTypeCondition: type =>
type == typeof(IAppDataContext) ||
type == typeof(ICloudService));
Container.RegisterDelegate<IMobileServiceClient>(factoryDelegate: r => r.Resolve<ICloudService>().Client,
reuse: Reuse.Singleton,
setup: Setup.With(allowDisposableTransient: true));
Container.Register<ILoginProvider<AADAccount>,LoginProvider>(Reuse.Singleton);
}
public class AwesomeAppCloudServiceOptions : IAzureCloudServiceOptions
{
public string AppServiceEndpoint => "https://yourappname.azurewebsites.net";
public string AlternateLoginHost => string.Empty;
public string LoginUriPrefix => string.Empty;
public HttpMessageHandler[] Handlers => new HttpMessageHandler[0];
}
public class AwesomeAppCustomerAppContext : DryIocCloudAppContext
{
public MyAppClient(IContainer container)
// We can optionally pass in a database name
: base(container, "myDatabaseName.db")
{
}
/*
* NOTE: This is architected to be similar to Entity Framework in that
* the CloudAppContext will look for properties that are ICloudSyncTable<>
* so that it can register the Model type with the SQLite Store.
*/
public ICloudSyncTable<Customer> Customers => SyncTable<Customer>();
public ICloudSyncTable<Invoice> Invoices => SyncTable<Invoice>();
public ICloudSyncTable<InvoiceItem> InvoiceItems => SyncTable<InvoiceItem>();
public ICloudTable<Feedback> Feedback => Table<Feedback>();
}
public class Customer : EntityData
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
}
public class Invoice : EntityData
{
public string CustomerId { get; set; }
}
public class InvoiceItem : EntityData
{
public string InvoiceId { get; set; }
public string ItemId { get; set; }
public int Quantity { get; set; }
}
public class Feedback : EntityData
{
public string Message { get; set; }
public string Status { get; set; }
}