Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does it make sense to use F# for BLL implementation?

Do you think it could be a good idea to use F# for implementation Business Logic Layer? I am going to use Entity Framework as 'data mapper' and implement UI logic using C#.

Any thought are welcome. I would appreciate any help!

Thanks.

P.S. What is a purpose of that? I am newbie in F# and would like to experiment with that Language (technology). I have to implement a relatively small project and it could be good to get F# experience.

like image 749
Budda Avatar asked Dec 09 '22 13:12

Budda


1 Answers

Implementing the "actual data processing" in F# is perhaps the most common use of F# currently, so implementing the business logic in F# seems like a good choice.

I don't think that you'll be able to use Entity Framework (easily) directly from F#, so you'll need to use C# to generate the data model and expose relevant data to F#. If you wanted to use LINQ to SQL then you can just generate the mapping in C# and write queries in F# using PowerPack (as Mitya suggests).

Perhaps the easiest thing to do would be to have three projects:

  • Data access layer in C# that simply uses Entity Framework and exposes the important data (using the IEnumerable type, which can be easily consumed from F#).

  • Business layer in F# that uses the data, performs the "actual processing" and exposes a couple of types that can be used from C#. If you declare a class in F# then it will be compiled just like any normal .NET class, so you can easily use it from C#. You just need to be careful not to use F# specific features in the public interface. A couple of suggestions would be to use delegates (instead of functions), class types and IEnumerable (called seq in F#) instead of functional lists.

  • User interface layer in C# that calls the types declared in F#. If you follow the simple rules above, then the C# code can easily call F# types.

As a side note - even though F# doesn't support designers, it can be quite great for user interface programming (see for example this article or my talk about Silverlight in F#). One thing you could do is to create your user interface in a C# library project, mark everything as public and then reference it from an F# project that actually controls the user interaction. However, this is a bit more advanced, so I think that starting with the business layer is a good idea.

like image 128
Tomas Petricek Avatar answered Dec 15 '22 00:12

Tomas Petricek