nicolas
nicolas

Reputation: 9805

nested type provider

I have one type provider that connects to the network to retrieve data. And produce (the fiction we call) 'static type' through type providers mechanism.

Of course, I might not always be connected. I might be raging in a private jet with satellite connection down.

Has anyone experience building an "offline type provider" which take (somehow) a type (from a type provider) as an input, stores its definition on disk, and provides you later with said type definition for easy access while on your way to Koh Phangan ?

Since types are not allowed as parameter to TP, I was thinking in providing assembly name + type name to be offlined.

Upvotes: 2

Views: 404

Answers (2)

Tomas Petricek
Tomas Petricek

Reputation: 243041

This is a tricky aspect of writing F# type providers. But I think the main problem is that when you're developing in a private jet and you're using type providers to access some external data source, then you won't be able to access the data.

Schema caching - If the type provider supports some form of schema caching (i.e. by storing the schema in a XML file like LINQ to SQL mentioned by @desco), then you'll be able to write some code and compile it, but you still won't be able to test the code. I think this makes schema caching less useful for the private-jet scenario. However, it is useful in scenario where you build code on a build server that does not have access to the schema.

Local data - For the private-jet scenario, you probably need some sort of local data (or a subset), to be actually able to test the code you write and then you can often point the type provider to your local copy (database, CSV or XML file etc.).

Meta-provider - I think the idea of having meta-provider is pretty cool - it should work to some extent - you would be able to cache the schema, but you probably wouldn't be able to cache the data (perhaps the values of properites, but I guess methods would not work). I think it should be possible to just pass the name of the provider to mock as an argument to your meta-provider. Something like:

type CachedDB = 
  SchemaCachingProvider<"FSharp.Data.TypeProviders.dll", "SqlDataConnection", "..">

I'm not aware of any plans for doing something like this, but if you started, I'm sure the FSharpX people would be interested in looking at it :-).

Upvotes: 2

desco
desco

Reputation: 16782

You can enhance your original type provider to work both in online and offline modes. I.e. provider tries to connect to data source and fetch schema, if successful schema is cached on disk (in some format that provider can understand). After that provider exposes types using schema information on disk. If for some reason connection to data source is not available - provider checks if cached schema exists and if yes - uses it. For example standard type providers (LINQ2SQL or EF) allow you to specify schema file that can be used if direct connection to database is not possible.

Upvotes: 2

Related Questions